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/">
<?xml version = '1.0'?>
<USER>
<ROW num="1">
<USER_ID>25214</USER_ID>
<LOGIN_ID>JDOE</LOGIN_ID>
<NAME_LAST>JOHN</NAME_LAST>
<NAME_FIRST>DOE</NAME_FIRST>
<NAME_MI>Q</NAME_MI>
<NAME_FI>A</NAME_FI>
<EMAIL>john.doe@email.com</EMAIL>
<OFFICE_PHONE>5551212</OFFICE_PHONE>
<OFFICE_STREET1>123 Main Street</OFFICE_STREET1>
</ROW> </USER>
( 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?
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,'<,>,"','<,>,"'),false)>
Note, however, that
...Copy link to clipboard
Copied
The document servers are available now.
Have a look at xmlParse: Adobe ColdFusion 9 * XmlParse
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,'<,>,"','<,>,"'),false)>
Note, however, that your XML would then contain an error. The processing instruction, "<?xml version = '1.0'?>", occurs twice.
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,'<,>,"','<,>,"'),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,'<,>,"','<,>,"')>
But this errors out:
<cfset listusers= xmlParse(myusers)>
(error parsing xml document)
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 |
| ||||||
fatalerrors |
| ||||||
status | NO | ||||||
warnings |
|
I might have to go about this another way.
Copy link to clipboard
Copied
Woo! Got it working by using rereplace() to strip out all the bad XML. Parse now works! Thanks!
Copy link to clipboard
Copied
You probably saw what I said earlier, namely:
The processing instruction, "<?xml version = '1.0'?>", occurs twice.
Copy link to clipboard
Copied
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.