Jump to content

Extracting Cdata From Xml


sbutt

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

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...