I have been asked to programme a method for importing data from xml files into our Coldfusion 8 website, I am new to using XML.
My method had been working however I encounted the following error:
Element NETWORKORDER.SECONDARYADDRESS.CONTACTNAME is undefined in MYDOC.
On investigation the node in the XML file was not present.
Is there a method I can use to resolve this error by checking if a node exists in the xml file, that works with my current code below?
<!--- Read XML file --->
<cffile action="read" file="D:\website\XML\#FileName#" variable="myxml">
<cfset mydoc = XmlParse(myxml)>
<!--- Extract Data from NDS XML File --->
<cfset aPrimaryContactName=(#mydoc.NetworkOrder.PrimaryAddress.ContactName#)>
<cfset aPrimaryContactNumber=(#mydoc.NetworkOrder.PrimaryAddress.ContactNumber#)>
<cfset aPrimaryContactNumber= tostring(#mydoc.NetworkOrder.PrimaryAddress.ContactNumber#)>
<cfset aPrimaryContactAddressLine1=(#mydoc.NetworkOrder.PrimaryAddress.line1#)>
<cfset aPrimaryContactAddressLine2=(#mydoc.NetworkOrder.PrimaryAddress.line2#)>
<cfset aPrimaryContactAddressLine3=(#mydoc.NetworkOrder.PrimaryAddress.line3#)>
<cfset aPrimaryContactAddressLine4=(#mydoc.NetworkOrder.PrimaryAddress.line4#)>
<cfset aPrimaryContactAddressLine5=(#mydoc.NetworkOrder.PrimaryAddress.line5#)>
<cfset aPrimaryContactCity=(#mydoc.NetworkOrder.PrimaryAddress.City#)>
<cfset aPrimaryContactPostcode=(#mydoc.NetworkOrder.PrimaryAddress.PostalCode#)>
<cfset aPrimaryContactCounty=(#mydoc.NetworkOrder.PrimaryAddress.CountrySubdivision#)>
<cfset aPrimaryContactCountryCode=(#mydoc.NetworkOrder.PrimaryAddress.CountryCode#)>
<cfset aPrimaryContactCountry=(#mydoc.NetworkOrder.SecondaryAddress.Country#)>
<cfset aSecondaryContactName=(#mydoc.NetworkOrder.SecondaryAddress.ContactName#)>
<cfset aSecondaryAttentionOfName=(#mydoc.NetworkOrder.SecondaryAddress.AttentionOfName#)>
<cfset aSecondaryContactNumber=(#mydoc.NetworkOrder.SecondaryAddress.ContactNumber#)>
<cfset aSecondaryContactAddressLine1=(#mydoc.NetworkOrder.SecondaryAddress.line1#)>
<cfset aSecondaryContactAddressLine2=(#mydoc.NetworkOrder.SecondaryAddress.line2#)>
<cfset aSecondaryContactAddressLine3=(#mydoc.NetworkOrder.SecondaryAddress.line3#)>
<cfset aSecondaryContactAddressLine4=(#mydoc.NetworkOrder.SecondaryAddress.line4#)>
<cfset aSecondaryContactAddressLine5=(#mydoc.NetworkOrder.SecondaryAddress.line5#)>
<cfset aSecondaryContactCity=(#mydoc.NetworkOrder.SecondaryAddress.City#)>
<cfset aSecondaryContactPostcode=(#mydoc.NetworkOrder.SecondaryAddress.PostalCode#)>
<cfset aSecondaryContactCounty=(#mydoc.NetworkOrder.SecondaryAddress.CountrySubdivision#)>
<cfset aSecondaryContactCountryCode=(#mydoc.NetworkOrder.SecondaryAddress.CountryCode#)>
<cfset aSecondaryContactCountry=(#mydoc.NetworkOrder.SecondaryAddress.Country#)>