Created
July 5, 2024 06:37
-
-
Save trycf/1083ac10e3f67758c4cd830c29422bcb to your computer and use it in GitHub Desktop.
TryCF Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- 2018-12-03 Convert XML string to JSON string in 1 line of code | |
Uses CF2016 /cfusion/lib/closure-compiler.jar (but library used is from 2009 and has been updated 12+ times) | |
If using CF10 (or want to use newer library), download newer JARs directly from the JSON-Java project & use JavaLoader: | |
https://github.com/stleary/JSON-java | |
https://search.maven.org/search?q=g:org.json%20AND%20a:json&core=gav | |
2023-07-25: This approach to consuming XML is not susceptible to the XML External Entity (XXE) vulnerability. | |
https://foundeo.com/security/guide/xml-external-entities/ | |
---> | |
<cfsavecontent variable="xmlText"><?xml version="1.0" encoding="utf-8"?> | |
<entry xml:base="https://vhblnds4ci.sap.belden.com:44300/sap/opu/odata/sap/ZOTC_ED_MAT_GETLIST_DETAIL_SRV/" xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"> | |
<id>https://vhblnds4ci.sap.belden.com:44300/sap/opu/odata/sap/ZOTC_ED_MAT_GETLIST_DETAIL_SRV/OUTPUT_ITEMDETAILSSet('')</id> | |
<title type="text">OUTPUT_ITEMDETAILSSet('')</title> | |
<updated>2024-07-04T10:56:34Z</updated> | |
<category term="ZOTC_ED_MAT_GETLIST_DETAIL_SRV.OUTPUT_ITEMDETAILS" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/> | |
<link href="OUTPUT_ITEMDETAILSSet('')" rel="self" title="OUTPUT_ITEMDETAILS"/> | |
<link href="OUTPUT_ITEMDETAILSSet('')/OrderItemsNav" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/OrderItemsNav" type="application/atom+xml;type=feed" title="OrderItemsNav"> | |
<m:inline> | |
<feed xml:base="https://vhblnds4ci.sap.belden.com:44300/sap/opu/odata/sap/ZOTC_ED_MAT_GETLIST_DETAIL_SRV/"> | |
<id>https://vhblnds4ci.sap.belden.com:44300/sap/opu/odata/sap/ZOTC_ED_MAT_GETLIST_DETAIL_SRV/OUTPUT_ITEMDETAILSSet('')/OrderItemsNav</id> | |
<title type="text">INPUT_ITEMNUMBERSSet</title> | |
<updated>2024-07-04T10:56:34Z</updated> | |
<author> | |
<name/> | |
</author> | |
<link href="OUTPUT_ITEMDETAILSSet('')/OrderItemsNav" rel="self" title="INPUT_ITEMNUMBERSSet"/> | |
<entry> | |
<id>https://vhblnds4ci.sap.belden.com:44300/sap/opu/odata/sap/ZOTC_ED_MAT_GETLIST_DETAIL_SRV/INPUT_ITEMNUMBERSSet('No%20valid%20itemnumber%20entered%28Not%20exist%20in%20S4%29')</id> | |
<title type="text">INPUT_ITEMNUMBERSSet('No%20valid%20itemnumber%20entered%28Not%20exist%20in%20S4%29')</title> | |
<updated>2024-07-04T10:56:34Z</updated> | |
<category term="ZOTC_ED_MAT_GETLIST_DETAIL_SRV.INPUT_ITEMNUMBERS" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/> | |
<link href="INPUT_ITEMNUMBERSSet('No%20valid%20itemnumber%20entered%28Not%20exist%20in%20S4%29')" rel="self" title="INPUT_ITEMNUMBERS"/> | |
<content type="application/xml"> | |
<m:properties> | |
<d:ItemNumber>CAF2106016</d:ItemNumber> | |
<d:MaterialDescription/> | |
<d:AdditionalDescription/> | |
<d:CustomerMaterialNumber/> | |
<d:NetAmount>0.0000 </d:NetAmount> | |
<d:UnitOfMeasure/> | |
<d:MinimumOrderQuantity>0.000 </d:MinimumOrderQuantity> | |
<d:EAN/> | |
<d:Status>No valid itemnumber entered(Not exist in S4)</d:Status> | |
</m:properties> | |
</content> | |
</entry> | |
<entry> | |
<id>https://vhblnds4ci.sap.belden.com:44300/sap/opu/odata/sap/ZOTC_ED_MAT_GETLIST_DETAIL_SRV/INPUT_ITEMNUMBERSSet('No%20valid%20itemnumber%20entered%28Not%20exist%20in%20S4%29')</id> | |
<title type="text">INPUT_ITEMNUMBERSSet('No%20valid%20itemnumber%20entered%28Not%20exist%20in%20S4%29')</title> | |
<updated>2024-07-04T10:56:34Z</updated> | |
<category term="ZOTC_ED_MAT_GETLIST_DETAIL_SRV.INPUT_ITEMNUMBERS" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/> | |
<link href="INPUT_ITEMNUMBERSSet('No%20valid%20itemnumber%20entered%28Not%20exist%20in%20S4%29')" rel="self" title="INPUT_ITEMNUMBERS"/> | |
<content type="application/xml"> | |
<m:properties> | |
<d:ItemNumber>CAF2106015</d:ItemNumber> | |
<d:MaterialDescription/> | |
<d:AdditionalDescription/> | |
<d:CustomerMaterialNumber/> | |
<d:NetAmount>0.0000 </d:NetAmount> | |
<d:UnitOfMeasure/> | |
<d:MinimumOrderQuantity>0.000 </d:MinimumOrderQuantity> | |
<d:EAN/> | |
<d:Status>No valid itemnumber entered(Not exist in S4)</d:Status> | |
</m:properties> | |
</content> | |
</entry> | |
</feed> | |
</m:inline> | |
</link> | |
<content type="application/xml"> | |
<m:properties> | |
<d:DivisionCode>CA01</d:DivisionCode> | |
<d:CustomerNumber>7000386</d:CustomerNumber> | |
<d:MeasureType>M</d:MeasureType> | |
<d:Language>ENG</d:Language> | |
<d:Status/> | |
</m:properties> | |
</content> | |
</entry> | |
</cfsavecontent> | |
<cfset entrycounter = 0 /> | |
<cfset artQuery = QueryNew("ItemNumber, MaterialDescription, AdditionalDescription, CustomerMaterialNumber, NetAmount, UnitOfMeasure, MinimumOrderQuantity,Status")/> | |
<cfset testCaseResults5XMLObj= xmlParse(xmlText)> | |
<cfset emp = testCaseResults5XMLObj.entry.XmlChildren> | |
<cfloop index="i" from="1" to="#arrayLen(emp)#"> | |
<cfif emp[i].XmlName EQ 'link'> | |
<cfset test = emp[i].XmlChildren/> | |
<cfif arraylen(test)> | |
<cfloop index="i" from="1" to="#arrayLen(test)#"> | |
<cfset minline = test[i].XmlChildren/> | |
<cfset feed = minline[i].XmlChildren/> | |
<cfloop index="feedindex" from="1" to="#arrayLen(feed)#"> | |
<cfif feed[feedindex].XmlName EQ 'entry'> | |
<cfset entrycounter = entrycounter + 1 /> | |
</cfif> | |
</cfloop> | |
<cfset queryAddRow(artQuery, entrycounter)/> | |
<cfset entryinside = 1> | |
<cfloop index="Feedindex" from="1" to="#arrayLen(feed)#"> | |
<cfif feed[feedindex].XmlName EQ 'entry'> | |
<cfset entryinside = entryinside + 1/> | |
<cfset entry = feed[feedindex].XmlChildren/> | |
<cfloop index="entryindex" from="1" to="#arrayLen(entry)#"> | |
<cfif entry[k].XmlName EQ 'content'> | |
<cfset content = entry[k].XmlChildren /> | |
<cfset properties = content[1].XmlChildren /> | |
<cfloop index="k" from="1" to="#arrayLen(content)#"> | |
<cfset properties = content[k].XmlChildren /> | |
<cfloop index="k" from="1" to="#arrayLen(properties)#"> | |
</cfloop> | |
</cfloop> | |
</cfif> | |
</cfloop> | |
</cfif> | |
</cfloop> | |
</cfloop> | |
</cfif> | |
</cfif> <br><br> | |
</cfloop> | |
<!--- | |
<cfloop index="k" from="1" to="#arrayLen(content)#"> | |
<cfset properties = content[k].XmlChildren /> | |
<cfdump var ="#properties[k]#"> | |
</cfloop> | |
---> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment