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

Extract And SET Values from XML File

Participant ,
Aug 03, 2011 Aug 03, 2011

I have XML string like this

<Request><Header><UserId>pgh</UserId><Token>05032015T1105144</Token></Header></Request>

How can I extract the <UserId> and <Token> values only?

So for the above string --I want the values

pgh

05032015T1105144

I want to set these 2 values to variables like this...everything else in the string goes away

<CFSET userid =pgh>

<CFSET token = 05032015T1105144>

So you START with this

<Request><Header><UserId>pgh</UserId><Token>05032015T1105144</Token></Header></Request>

And END with this

<CFSET userid =pgh>

<CFSET token = 05032015T1105144>

966
Translate
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
Valorous Hero ,
Aug 03, 2011 Aug 03, 2011

Looks like this is related to your other thread.  How far did you get with things, were you able to parse the XML?

Translate
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
Participant ,
Aug 03, 2011 Aug 03, 2011

Yes it is related to the post you mention.

I was able to extract the info....

now the partner firm is requesting that I send back this xml (see below) to them...any idea on how I would do that?

</Response

Translate
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
Valorous Hero ,
Aug 03, 2011 Aug 03, 2011

The forum must have eaten your code.  Try using the insert code button  ie  ">>".

now the partner firm is requesting that I send back this xml (see below) to them...any idea on how I would do that?

But we seem to have switched gears. Are you saying you have figured out how to extract values from your XML and now need to generate XML instead?

Translate
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
Participant ,
Aug 03, 2011 Aug 03, 2011

Yes I HAVE figured out how to extract the needed values from the xml..

NOW I need to send back this xml (see below) to them...any idea on how I would do that?

Patrick Hutchinson

Translate
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
Valorous Hero ,
Aug 03, 2011 Aug 03, 2011

Well FIRST you need to figure out how to post your code/xml so we can actually see it ...

Translate
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
Participant ,
Aug 03, 2011 Aug 03, 2011
LATEST

Well actually...a new problem keeps arising as I move forward.

I finally have been able to extract the xml and send a request back to the partners server...

So all of that has been resolved.

Now the partner tells me that my <cfhttp request is A NEW SESSION and that I needed to keep the same session that

Patrick Hutchinson

www.1design.com

Office: 804-360-0695

Cell: 804-370-6873

Email: pat@1design.com

Translate
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
Enthusiast ,
Aug 03, 2011 Aug 03, 2011

There are a few ways you could do this, but the easiest is probably to use the XmlParse function, eg:

<cfset xmlObj = XmlParse(xml)>

You should then be able to do something like this:

<cfoutput>

#xmlObj.XmlRoot.Header.UserId#

#xmlObj.XmlRoot.Header.Token#

</cfoutput>

You can do a cfdump on the xmlObj to see all the variables at your disposal. You might need to append an XML declaration to the beginning of your XML, eg:

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

Translate
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