Created
July 5, 2024 06:26
-
-
Save trycf/9615d47914e42eba9196c64c56e0c6f6 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 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="j" from="1" to="#arrayLen(feed)#"> | |
<cfif feed[j].XmlName EQ 'entry'> | |
<cfset entry = feed[j].XmlChildren/> | |
<cfloop index="k" from="1" to="#arrayLen(entry)#"> | |
<cfif entry[k].XmlName EQ 'content'> | |
<cfset content = entry[k].XmlChildren /> | |
<cfset queryAddRow(artQuery, entry)/> | |
<cfdump var="#arraylen(content)#"/> | |
<cfset properties = content[1].XmlChildren /> | |
<cfloop index="k" from="1" to="#arrayLen(content)#"> | |
<cfset properties = content[k].XmlChildren /> | |
<cfdump var="#properties#"/> | |
</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