What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 130 Stack Exchange communities.

How does one post XML in Stack Overflow?

I've tried using <pre> and backticks to no avail. I suppose that I could go through and try indent every line by four spaces but that would get really tedious really fast.

Is there any way to easily post XML in a question?

Edit:

URL of question: http://stackoverflow.com/questions/1337316/configuring-elmah-unrecognized-config-section-error

I tried putting the XML inside <code> tags and that sliced and diced the XML in a very odd fashion.

share|improve this question
    
Why not post to where you are having the issue? –  GEOCHET Aug 26 '09 at 20:43

3 Answers 3

up vote 6 down vote accepted

Why not just use the code block?

  • There is a code button in the editor toolbar:
  • You could highlight the XML and press ctrl k
  • You could indent the XML with 4 spaces.

Edit:

In your case, you are getting close to exceeding the maximum length of a post. You should be more terse or host it externally.


Edit:

I fixed your post for you by highlighting the XML and clicking the button like I said.


More information:

http://meta.stackoverflow.com/editing-help

share|improve this answer
    
Or Ctrl-K, or use a real text editor to do the indent, or the toolbar button... –  Joel Coehoorn Aug 26 '09 at 20:44
    
Sorry about that; I thought I had solved it by putting the XML inside a code block only to realize upon re-reading the post that much of the XML had been sliced off. –  Zian Choy Aug 26 '09 at 20:49
    
If the length has been exceeded, why does it remove a piece in the middle and not cut off the end? –  Brandon Aug 26 '09 at 20:53
    
See edits. OP did not read my post apparently. –  GEOCHET Aug 26 '09 at 20:53
    
Thats odd, I tried adding 4 spaces, and all it did was move the line numbers over, the XML code still didn't show up in the preview. –  Brandon Aug 26 '09 at 20:55
    
I've read your post several times but I probably missed one of your edit blurbs. Sorry about that. It looks like the XML part is back at last. Thank you so much. –  Zian Choy Aug 26 '09 at 20:59
    
@Zian: You clearly did not read it. All I did was highlight your stuff and click the code button. –  GEOCHET Aug 26 '09 at 21:03
    
@Rich B I thought the code block button simply inserted <code> tags. Until I dived into the source code of the post (so to speak), I didn't realize that the code block button inserted spaces. –  Zian Choy Aug 26 '09 at 21:07
    
Note that in case the XML does not get recognized despite the code block, one can use <!-- language: lang-xml -->. –  eis Jan 13 at 12:54

Another potential cause of XML not being displayed correctly is if the code is part of a list; either numerated #) or bulleted -. In this case you need 8 spaces in front of the XML code for it to be escaped instead of the standard 4 spaces.

  • For example, unescaped XML:

    Not escaped

  • Example, correctly escaped:

    <style>Correctly escaped</style>
    

As described in this post: Post XML in answer

share|improve this answer

Depending on how much you are trying to post, using an outside repository like PasteBin may be your most efficient method.

share|improve this answer
1  
Or he could just use a code block on SO.com and not make external links for no reason. –  GEOCHET Aug 26 '09 at 20:47
1  
Or when the post is too big he could use PasteBin :) –  TheTXI Aug 26 '09 at 20:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .