XML: Variable # nodes problem...
i have nodes in xml file this:
<?xml...
<listings xmlns...
<listing>
<name>john doe</name>
<address format="simple">
<component name="addr1">155 main street</component>
<component name="city">new york</component>
<component name="province">ny</component>
<component name="postal_code">99999</component>
</address>
<phone type="main">(555) 555-5555</phone>
<phone type="fax">(444) 444-4444</phone>
</listing>
</listings>
the problem is, if 4 address lines aren't there, , if don't send fax or phone number. simpler xml elements, i'm able stuff , works:
<cfif not structkeyexists(mydoc.listings.listing , "name")>
<cfoutput>record #i#: name doesn't exist!</cfoutput><br>
<cfset mydoc.listings.listing.name = xmlelemnew(mydoc,"name")>
<cfset mydoc.listings.listing .name.xmltext = "unknown">
</cfif>
if "name" isn't in file, sets "unknown".
but can't code work more complicated structures address , phone above. if following, says phone isn't present, though is:
<cfif not structkeyexists(mydoc.listings.listing,"phone[1]")>
<cfoutput>record #i#: phone_main doesn't exist!</cfoutput><br>
<cfset mydoc.listings.listing .phone[1].xxx = xmlelemnew(mydoc,"xxx")>
<cfset mydoc.listings.listing.phone[1].xxx.xmltext = "0">
</cfif>
basically problem is, if don't insert node, coldfusion throws exception when try put in query:
<cfset temp = querysetcell(storequery, "phone_main",
#mydoc.listings.listing .phone[1].xmltext#, #i#)>
maybe there's better work-around problem inserting nodes missing nodes? tried using <cfparam> default values, no luck there. throws exception too. if try using xmlsearch , item missing, throws exception.
any appreciated.
thanks!
mike
<?xml...
<listings xmlns...
<listing>
<name>john doe</name>
<address format="simple">
<component name="addr1">155 main street</component>
<component name="city">new york</component>
<component name="province">ny</component>
<component name="postal_code">99999</component>
</address>
<phone type="main">(555) 555-5555</phone>
<phone type="fax">(444) 444-4444</phone>
</listing>
</listings>
the problem is, if 4 address lines aren't there, , if don't send fax or phone number. simpler xml elements, i'm able stuff , works:
<cfif not structkeyexists(mydoc.listings.listing , "name")>
<cfoutput>record #i#: name doesn't exist!</cfoutput><br>
<cfset mydoc.listings.listing.name = xmlelemnew(mydoc,"name")>
<cfset mydoc.listings.listing .name.xmltext = "unknown">
</cfif>
if "name" isn't in file, sets "unknown".
but can't code work more complicated structures address , phone above. if following, says phone isn't present, though is:
<cfif not structkeyexists(mydoc.listings.listing,"phone[1]")>
<cfoutput>record #i#: phone_main doesn't exist!</cfoutput><br>
<cfset mydoc.listings.listing .phone[1].xxx = xmlelemnew(mydoc,"xxx")>
<cfset mydoc.listings.listing.phone[1].xxx.xmltext = "0">
</cfif>
basically problem is, if don't insert node, coldfusion throws exception when try put in query:
<cfset temp = querysetcell(storequery, "phone_main",
#mydoc.listings.listing .phone[1].xmltext#, #i#)>
maybe there's better work-around problem inserting nodes missing nodes? tried using <cfparam> default values, no luck there. throws exception too. if try using xmlsearch , item missing, throws exception.
any appreciated.
thanks!
mike
still not having luck this, , problems compounding find more of these complex xml statements in feed. on right track appreciated.
More discussions in Advanced Techniques
adobe
Comments
Post a Comment