MissouriTiger
Programmer
I would be grateful for some advice. I'm an Asp developer & I use XML about twice a year, just often enough to get me into trouble.
I'm building a Google Checkout integration. I wrote a script which receives an XML doc from GOogle & extracts data from it.
Problem: Certain nodes may, or may not, contain a value, but the tag is always there. So my script generates an error when attempting to access a non-exstent child node (an optional value that isn't there). What I am doing at this poiont is just "On Error resume Next", but i hate to do that. Is there a different syntax I can use that won't throw an error when the value isn't there?
Example XML:
<email>joe@bloe.com</email>
<contact-name>Joe Bloe</contact-name>
<company-name />
Example Code:
pEmail = objDomGN.getElementsByTagName("email")(0).childNodes(0).nodeValue
pContact = objDomGN.getElementsByTagName("contact-name")(0).childNodes(0).nodeValue
pCompany = objDomGN.getElementsByTagName("company-name")(0).childNodes(0).nodeValue
The last line of code causes the error, since in this case there is no company name. How can I fix this not to cause an error?
Any advice will be greatly appreciated.
Greg Norris
Software Developer & all around swell guy
__________________________________________________
Constructed from 100% recycled electrons.
I'm building a Google Checkout integration. I wrote a script which receives an XML doc from GOogle & extracts data from it.
Problem: Certain nodes may, or may not, contain a value, but the tag is always there. So my script generates an error when attempting to access a non-exstent child node (an optional value that isn't there). What I am doing at this poiont is just "On Error resume Next", but i hate to do that. Is there a different syntax I can use that won't throw an error when the value isn't there?
Example XML:
<email>joe@bloe.com</email>
<contact-name>Joe Bloe</contact-name>
<company-name />
Example Code:
pEmail = objDomGN.getElementsByTagName("email")(0).childNodes(0).nodeValue
pContact = objDomGN.getElementsByTagName("contact-name")(0).childNodes(0).nodeValue
pCompany = objDomGN.getElementsByTagName("company-name")(0).childNodes(0).nodeValue
The last line of code causes the error, since in this case there is no company name. How can I fix this not to cause an error?
Any advice will be greatly appreciated.
Greg Norris
Software Developer & all around swell guy
__________________________________________________
Constructed from 100% recycled electrons.