0

I have this XML:

  <school>
   <name>Big school</name>
   <located>somewhere</located>
   <age>163</age>
   <students>53354</students>
 </school>

I want to add new element to this XML and display it in a browser. I can use DOM methods to add new element but I do not know how to display it in a browser. I found this http://www.ehow.com/how_5941838_display-xml-javascript.html but I did not make it work.

I want to see something like this in a browser:

<school>
   <name>Big school</name>
   <located>somewhere</located>
   <age>163</age>
   <students>53354</students>
   <teachers>18752</teachers>
 </school>

Can i do this in some simple way?

1 Answers1

0

You could just wrap it in a xmp element, which will preserve the formatting and display the markup (not interpret it as HTML).

<xmp>
    <school>
        <name>Big school</name>
        <located>somewhere</located>
        <age>163</age>
        <students>53354</students>
        <teachers>18752</teachers>
    </school>
</xmp>

Note though that this tag is non standard and has been deprecated as the others noted, but it still works in all major browsers and there seems to be no decent alternative to it (without using JS or escaping the content).

HaukurHaf
  • 13,522
  • 5
  • 44
  • 59
  • 1
    The W3 wiki [says that](https://www.w3.org/wiki/HTML/Elements/xmp) “the `` element is a non-standard element” and “don’t use it”, and MDN [says that](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/xmp) it is an obsolete feature. Perhaps you could add some extra detail to your answer to explain why it is justified? – icktoofay May 31 '14 at 23:23
  • The accepted answer here: http://stackoverflow.com/questions/16783708/how-to-display-raw-html-code-in-pre-or-something-like-it-but-without-escaping-it recommends using it. I did not realize it's non standard and that it has been deprecated, but as far as I can tell it's still supported in all major browsers and there really is no other alternative available which is as easy to use. – HaukurHaf May 31 '14 at 23:31
  • Sorry but this is not what i seek. Problem is that I will use DOM methods to add new element and then i need that to display it. – David Brož May 31 '14 at 23:48