• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How do I deal with an XML file that uses html characters?

Contributor ,
May 28, 2014 May 28, 2014

Copy link to clipboard

Copied

I need to pull a userlist for my web app, and that involves invoking a web service on the authentication server.  I've managed to do just that, but the XML file I'm given to deal with looks like this:

<?xml version="1.0" encoding="UTF-8"?>

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<soapenv:Body><ns1:getAllUserInfoResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://web.ws">

<getAllUserInfoReturn xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">

&lt;?xml version = '1.0'?&gt;

&lt;USER&gt;

&lt;ROW num=&quot;1&quot;&gt;

&lt;USER_ID&gt;25214&lt;/USER_ID&gt;

&lt;LOGIN_ID&gt;JDOE&lt;/LOGIN_ID&gt;

&lt;NAME_LAST&gt;JOHN&lt;/NAME_LAST&gt;

&lt;NAME_FIRST&gt;DOE&lt;/NAME_FIRST&gt;

&lt;NAME_MI&gt;Q&lt;/NAME_MI&gt;

&lt;NAME_FI&gt;A&lt;/NAME_FI&gt;

&lt;EMAIL&gt;john.doe@email.com&lt;/EMAIL&gt;

&lt;OFFICE_PHONE&gt;5551212&lt;/OFFICE_PHONE&gt;

&lt;OFFICE_STREET1&gt;123 Main Street&lt;/OFFICE_STREET1&gt;

&lt;/ROW&gt; &lt;/USER&gt;

( etc )

</getAllUserInfoReturn>

</ns1:getAllUserInfoResponse>

</soapenv:Body>

</soapenv:Envelope>

I need to loop through this and get usernames, ids, rights, etc, but with it looking like that, I have my work cut out for me (I think).  I'm not sure if there's an easy way to replace entities in an XML file (the docs seem to be down), and if there is, I don't know about it.

Any ideas?

Views

2.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 29, 2014 May 29, 2014

BreakawayPaul wrote:

I need to loop through this and get usernames, ids, rights, etc, but with it looking like that, I have my work cut out for me (I think).  I'm not sure if there's an easy way to replace entities in an XML file

Assuming you have already obtained the XML file using something like <cffile action="read" variable="xmlFile">, then the following single line of code is sufficient:

<cfset xmlDoc=xmlParse(replaceList(xmlFile,'&lt;,&gt;,&quot;','<,>,"'),false)>

Note, however, that

...

Votes

Translate

Translate
Advocate ,
May 28, 2014 May 28, 2014

Copy link to clipboard

Copied

The document servers are available now.

Have a look at xmlParse: Adobe ColdFusion 9 * XmlParse

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2014 May 29, 2014

Copy link to clipboard

Copied

BreakawayPaul wrote:

I need to loop through this and get usernames, ids, rights, etc, but with it looking like that, I have my work cut out for me (I think).  I'm not sure if there's an easy way to replace entities in an XML file

Assuming you have already obtained the XML file using something like <cffile action="read" variable="xmlFile">, then the following single line of code is sufficient:

<cfset xmlDoc=xmlParse(replaceList(xmlFile,'&lt;,&gt;,&quot;','<,>,"'),false)>

Note, however, that your XML would then contain an error. The processing instruction, "<?xml version = '1.0'?>", occurs twice.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 29, 2014 May 29, 2014

Copy link to clipboard

Copied

Eddie Lotter wrote:

The document servers are available now.

Have a look at xmlParse: Adobe ColdFusion 9 * XmlParse

Is this the same for CF8 (which we're currently stuck on)?

BKBK wrote:

Assuming you have already obtained the XML file using something like <cffile action="read" variable="xmlFile">, then the following single line of code is sufficient:

<cfset xmlDoc=xmlParse(replaceList(xmlFile,'&lt;,&gt;,&quot;','<,>,"'),false)>

Note, however, that your XML would then contain an error. The processing instruction, "<?xml version = '1.0'?>", occurs twice.

I'm getting the XML file from a web service, using cfhttp.  As a result, my data is contained in userlist.filecontent.

I can do this to get rid of the escaped characters (thanks):

<cfset myusers= replaceList(userlist.filecontent,'&lt;,&gt;,&quot;','<,>,"')>

But this errors out:

<cfset listusers= xmlParse(myusers)>

(error parsing xml document)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 29, 2014 May 29, 2014

Copy link to clipboard

Copied

Ew, it looks like the problem is with the XML format itself.  I did xmlvalidate() and got this:

struct
errors
array
1 [Error] :1:214: cvc-elt.1: Cannot find the declaration of element 'soapenv:Envelope'.
2 [Error] :1:454: cvc-elt.4.2: Cannot resolve 'soapenc:string' to a type definition for element 'getAllUserInfoReturn'.
fatalerrors
array
1 [Fatal Error] :1:459: The processing instruction target matching "[xX][mM][lL]" is not allowed.
status NO
warnings
array [empty]

I might have to go about this another way.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 29, 2014 May 29, 2014

Copy link to clipboard

Copied

Woo! Got it working by using rereplace() to strip out all the bad XML.  Parse now works! Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2014 May 29, 2014

Copy link to clipboard

Copied

You probably saw what I said earlier, namely:

The processing instruction, "<?xml version = '1.0'?>", occurs twice.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 29, 2014 May 29, 2014

Copy link to clipboard

Copied

LATEST

Yep, but I didn't realize until I tried it that it would prevent the entire thing from working.

This is my first time really working in-depth with XML formatted data.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation