I am trying to parse a XML string with browser’s built in parser using JavaScript. My XML string looks like 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 a simple JavaScript code just to check whether parser is parsing my XML properly and converting it into valid XML DOM. JavaScript code looks like this:
parser = new DOMParser();
xmlDoc = parser.parseFromString(text, "text/xml");
x = xmlDoc.documentElement.childNodes;
document.getElementById("Text1").value = x[3].nodeName;
Here “text” is above XML. This code means nothing. I just wanted to test someting simple at first. I tested the XML at w3school.com for validity and it didnt give me error so i suppose there is no error in XML.
The following works for me. I am using Chrome 20.0.1132.21 beta-m.