Jump to content

Extracting Cdata From Xml


sbutt
 Share

Recommended Posts

Hi All, I have a following xml:

<?xml version="1.0" encoding="UTF-8"?><ForwardRequestResponse xmlns:m="http://webservices.kuoni.ch">	<ForwardRequestResult><![CDATA[<?xml version="1.0" encoding="windows-1252"?><Response Version="2.5" From="KUONEKA0" To="CETS" TermId="XXXXXX" Date="18062009" Time="163523" Type="ERROR" Confirm="X" Agent="XXXXXX" Lang="EN" UserCode="X" UserType="X" UserName="X" UserFirstName="X" Mode="X"><Err><ErrorNr>9999</ErrorNr><ErrorText>Fehlerhafter Request</ErrorText><ErrorText>element <Request> attribute: TermId is too long</ErrorText></Err></Response>]]></ForwardRequestResult></ForwardRequestResponse>

And I want to extract a CDATA out of it i.e.

<?xml version="1.0" encoding="windows-1252"?><Response Version="2.5" From="KUONEKA0" To="CETS" TermId="XXXXXX" Date="18062009" Time="163523" Type="ERROR" Confirm="X" Agent="XXXXXX" Lang="EN" UserCode="X" UserType="X" UserName="X" UserFirstName="X" Mode="X">	<Err>		<ErrorNr>9999</ErrorNr>		<ErrorText>Fehlerhafter Request</ErrorText>		<ErrorText>element <Request> attribute: TermId is too long</ErrorText>	</Err></Response>

Could someone please give me some pointers on how to do it?

Link to comment
Share on other sites

EDITMy mistake. I was thinking of Javascript.******************************To access the CDATA node, just access the parent element and then get the first child of it:

var CDATA = xmlDoc.getElementsByTagName("ForwardRequestResult").item(0).firstChild

To get the data contained in the CDATA node, just use the data property of the CDATA node.

alert(CDATA.data);

Unfortunately, Opera doesn't support any CDATA methods or properties

Edited by Ingolme
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...