I am trying to parse some XML in Javascript on firefox. I get the error ‘firstchild has no properties’.
The XML looks like this: -
- <AddressSearc h>
- <Summary>
<Total>30</Total>
<Pages>1</Pages>
<Page>1</Page>
<PageLength>200 </PageLength>
- <Range>
<Start>1</Start>
<End>30</End>
</Range>
- <InputValues>
<PostCode>sk1 4 6ld</PostCode>
</InputValues>
</Summary>
- <Address>
<PrimaryName />
<PrimaryNumber> 12A</PrimaryNumber>
<UPRN>100011577 044</UPRN>
<DESCRIPTION>MO TTRAM MOOR</DESCRIPTION>
<LOC />
<TOWN>MOTTRAM </TOWN>
<POSTTOWN>HYD E</POSTTOWN>
<POSTCODE>SK1 4 6LD</POSTCODE>
<X>399595</X>
<Y>395775</Y>
</Address>
My code is :-
AddressElements = rootNode.childN odes.item(1);
if (browsername == "Firefox") {
Northing = AddressElements .childNodes.ite m(en).firstChil d.nodeValue;
} else {
Northing = AddressElements .childNodes.ite m(en).text;
}
This works ok until the code hits the XML line <PrimaryName />
If I check for the nodename equal to fields that are always present ( X for example) the code works ok.
How can I check for the node having no properties?
The XML looks like this: -
- <AddressSearc h>
- <Summary>
<Total>30</Total>
<Pages>1</Pages>
<Page>1</Page>
<PageLength>200 </PageLength>
- <Range>
<Start>1</Start>
<End>30</End>
</Range>
- <InputValues>
<PostCode>sk1 4 6ld</PostCode>
</InputValues>
</Summary>
- <Address>
<PrimaryName />
<PrimaryNumber> 12A</PrimaryNumber>
<UPRN>100011577 044</UPRN>
<DESCRIPTION>MO TTRAM MOOR</DESCRIPTION>
<LOC />
<TOWN>MOTTRAM </TOWN>
<POSTTOWN>HYD E</POSTTOWN>
<POSTCODE>SK1 4 6LD</POSTCODE>
<X>399595</X>
<Y>395775</Y>
</Address>
My code is :-
AddressElements = rootNode.childN odes.item(1);
if (browsername == "Firefox") {
Northing = AddressElements .childNodes.ite m(en).firstChil d.nodeValue;
} else {
Northing = AddressElements .childNodes.ite m(en).text;
}
This works ok until the code hits the XML line <PrimaryName />
If I check for the nodename equal to fields that are always present ( X for example) the code works ok.
How can I check for the node having no properties?
Comment