I'm a newbie to XML so I tried to create my first "hello-world". Actually I already failed here. The Code returns 'null'. I'm aware of the white-space bug and I actually think, that I avoided it. So have a look:
Expand|Select|Wrap|Line Numbers
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
- <head>
- <title>JavaScript und XML</title>
- <script type="text/javascript">
- //<![CDATA[
- var loadXML = function(xmlDoc)
- {
- if (window.ActiveXObject)
- {
- xml = new ActiveXObject("Microsoft.XMLDOM");
- xml.async = false;
- xml.load(xmlDoc);
- parseXML();
- }
- else if (document.implementation && document.implementation.createDocument)
- {
- xml = document.implementation.createDocument("","",null);
- xml.async = false;
- xml.onload = parseXML;
- xml.load(xmlDoc);
- }
- else
- {
- alert("Can't open XML-Page.");
- }
- }
- window.onload = function()
- {
- loadXML("blumen.xml");
- }
- var parseXML = function()
- {
- var x=xml.documentElement.getElementsByTagName('name')[0].nodeValue;
- alert(x);
- }
- //]]>
- </script>
- </head>
- <body>
- </body>
- </html>
Expand|Select|Wrap|Line Numbers
- <?xml version="1.0" ?>\
- <root>\
- <blume>\
- <name>Rose</name>\
- <preis>1.10</preis>\
- </blume>\
- <blume>\
- <name>Tulpe</name>\
- <preis>0.90</preis>\
- </blume>\
- </root>
Thanks for ur help!