Jump to content

Extracting Cdata From Xml


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...