Created
March 25, 2014 00:26
-
-
Save bennadel/9752387 to your computer and use it in GitHub Desktop.
Stripping XML Name Spaces And Node Prefixes From ColdFusion XML Data (To Simplify XPath)
This file contains hidden or 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
<!--- Store the XStandard SOAP XML. ---> | |
<cfsavecontent variable="strXml"> | |
<?xml version="1.0" encoding="UTF-8"?> | |
<soap:Envelope | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:xsd="http://www.w3.org/2001/XMLSchema" | |
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> | |
<soap:Body> | |
<doDirectorySearch | |
xmlns="http://xstandard.com/2004/web-services"> | |
<lang>en</lang> | |
<searchFor>Smith</searchFor> | |
<filterBy>staff</filterBy> | |
</doDirectorySearch> | |
</soap:Body> | |
</soap:Envelope> | |
</cfsavecontent> |
This file contains hidden or 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
<!--- | |
Parse the XStandard SOAP request XML into a ColdFusion XML | |
document object. Be sure to trim the XML so that it | |
parses properly. | |
---> | |
<cfset xmlRequest = XmlParse( | |
strXml.Trim() | |
) /> | |
<!--- Search for the "searchFor" XML node using XPath. ---> | |
<cfset arrSearchNodes = XmlSearch( | |
xmlRequest, | |
"//searchFor" | |
) /> |
This file contains hidden or 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
<!--- Search for "searchFor" XML nodes using XPath. ---> | |
<cfset arrSearchNodes = XmlSearch( | |
xmlRequest, | |
"//*[name()='searchFor']" | |
) /> |
This file contains hidden or 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
<!--- | |
Strip out the tag prefixes. This will convert tags from the | |
form of soap:nodeName to JUST nodeName. This works for both | |
openning and closing tags. | |
---> | |
<cfset strXml = strXml.ReplaceAll( | |
"(</?)(\w+:)", | |
"$1" | |
) /> | |
<!--- | |
Remove all references to XML name spaces. These are node | |
attributes that begin with "xmlns:". | |
---> | |
<cfset strXml = strXml.ReplaceAll( | |
"xmlns(:\w+)?=""[^""]*""", | |
"" | |
) /> |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<Envelope> | |
<Body> | |
<doDirectorySearch> | |
<lang>en</lang> | |
<searchFor>Smith</searchFor> | |
<filterBy>staff</filterBy> | |
</doDirectorySearch> | |
</Body> | |
</Envelope> |
This file contains hidden or 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
<!--- | |
Parse the XStandard SOAP request XML into a ColdFusion XML | |
document object. Be sure to trim the XML so that it | |
parses properly. | |
---> | |
<cfset xmlRequest = XmlParse( | |
strXml.Trim() | |
) /> | |
<!--- Search for the "searchFor" XML node using XPath. ---> | |
<cfset arrSearchNodes = XmlSearch( | |
xmlRequest, | |
"//searchFor" | |
) /> | |
<!--- Dump out the search results. ---> | |
<cfdump | |
var="#arrSearchNodes#" | |
label="searchFor XPath Search Results" | |
/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment