javascript - XML Parsing Error: not well-formed while parsing XML string with browser's built in parser -


i trying parse xml string browser's built in parser using javascript. xml string looks this:

<?xml version='1.0' encoding='utf-8' ?> <xsd:schema xmlns:xsd='http://www.w3.org/2001/xmlschema'             xmlns:xsi='http://www.w3.org/2001/xmlschema-instance'             xsi:schemalocation='http://www.w3.org/2001/xmlschema xmlschema.xsd'             elementformdefault='qualified'             version='1.0'> <xsd:element name='probemetadata' type='oasis.system.processor.linuxprocessorprobe' /> <xsd:complextype name='oasis.system.processor.linuxprocessorprobe'> <xsd:complexcontent> <xsd:extension base='oasis.system.processor.processorprobe'> <xsd:sequence>     <xsd:element name='nice_time' type='xsd:unsignedlong'  />     <xsd:element name='iowait_time' type='xsd:unsignedlong'  />     <xsd:element name='irq_time' type='xsd:unsignedlong'  />     <xsd:element name='soft_irq_time' type='xsd:unsignedlong'  /> </xsd:sequence> </xsd:extension> </xsd:complexcontent> </xsd:complextype> <xsd:complextype name='oasis.system.processor.processorprobe'> <xsd:sequence>     <xsd:element name='idle_time' type='xsd:unsignedlong'  />     <xsd:element name='system_time' type='xsd:unsignedlong'  />     <xsd:element name='user_time' type='xsd:unsignedlong'  /> </xsd:sequence> </xsd:complextype> </xsd:schema> 

i wrote simple javascript code check whether parser parsing xml , converting valid xml dom. javascript code looks this:

parser = new domparser(); xmldoc = parser.parsefromstring(text, "text/xml");  x = xmldoc.documentelement.childnodes;  document.getelementbyid("text1").value = x[3].nodename; 

here "text" above xml. code means nothing. wanted test someting simple @ first. tested xml @ w3school.com validity , didnt give me error suppose there no error in xml.

the following works me. using chrome 20.0.1132.21 beta-m.

<html> <head>     <script>         function test(){             var text = "<?xml version='1.0' encoding='utf-8' ?>\r\n"             + "<xsd:schema xmlns:xsd='http://www.w3.org/2001/xmlschema'\r\n"             + "            xmlns:xsi='http://www.w3.org/2001/xmlschema-instance'\r\n"             + "            xsi:schemalocation='http://www.w3.org/2001/xmlschema xmlschema.xsd'\r\n"             + "            elementformdefault='qualified'\r\n"             + "            version='1.0'>\r\n"             + "<xsd:element name='probemetadata' type='oasis.system.processor.linuxprocessorprobe' />\r\n"             + "<xsd:complextype name='oasis.system.processor.linuxprocessorprobe'>\r\n"             + "<xsd:complexcontent>\r\n"             + "<xsd:extension base='oasis.system.processor.processorprobe'>\r\n"             + "<xsd:sequence>\r\n"             + "    <xsd:element name='nice_time' type='xsd:unsignedlong'  />\r\n"             + "    <xsd:element name='iowait_time' type='xsd:unsignedlong'  />\r\n"             + "    <xsd:element name='irq_time' type='xsd:unsignedlong'  />\r\n"             + "    <xsd:element name='soft_irq_time' type='xsd:unsignedlong'  />\r\n"             + "</xsd:sequence>\r\n"             + "</xsd:extension>\r\n"             + "</xsd:complexcontent>\r\n"             + "</xsd:complextype>\r\n"             + "<xsd:complextype name='oasis.system.processor.processorprobe'>\r\n"             + "<xsd:sequence>\r\n"             + "    <xsd:element name='idle_time' type='xsd:unsignedlong'  />\r\n"             + "    <xsd:element name='system_time' type='xsd:unsignedlong'  />\r\n"             + "    <xsd:element name='user_time' type='xsd:unsignedlong'  />\r\n"             + "</xsd:sequence>\r\n" + "</xsd:complextype>\r\n"             + "</xsd:schema>"             parser = new domparser();             xmldoc = parser.parsefromstring(text, "text/xml");             x = xmldoc.documentelement.childnodes;             document.getelementbyid("text1").value = x[3].nodename;                   }     </script> </head> <body>     <input type="button" value="click" onclick="test()"/>     <input type="text" name="text1" id="text1"/> </body> </html> 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -