Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Parsing CDATA

Status
Not open for further replies.

AlexTekTip

Programmer
Aug 30, 2004
17
US
I have an xml data document that I need to parse that involves CDATA sections. How do I go about it? I need to specifically parse the two CDATA section that currently hold "TEST" in them (See below).

Thank YOU!!


<?xml version="1.0" encoding="ISO-8859-1" ?>
- <Report cgidir="/cgi-lawson/" executable="getattachrec.exe" productline="QAS" filename="APINVOICE" token="Token" keynbr="KeyNbr">
- <QueryBase exepath="/cgi-lawson/writeattach.exe">
- <![CDATA[ _OUT=XML&_PDL=QAS&_FN=APINVOICE&_IN=APISET1&
]]>
</QueryBase>
- <WinTitle>
- <![CDATA[ <NULL>
]]>
</WinTitle>
- <ParentRec>
- <QueryVal>
- <![CDATA[ _AK=yMjh
]]>
</QueryVal>
- <RecAtt Action="Add">
- <AttName>
- <![CDATA[ Add Attach
]]>
</AttName>
- <QueryVal>
- <![CDATA[ K1=9000&K2= 55413&K3=ASWTEST101504C&K4=000&K5=0000&_DATA=TRUE&_OPM=M&
]]>
</QueryVal>
</RecAtt>
- <RecAtt Action="">
- <AttName>
- <![CDATA[ TEST
]]>
</AttName>
- <AttData>
- <![CDATA[ TEST
]]>
</AttData>
- <QueryVal>
- <![CDATA[ K1=9000&K2= 55413&K3=ASWTEST101504C&K4=000&K5=0000&_ATYP=C&_AUDT=N&_KS=zz&_OPM=A&_DATA=TRUE&
]]>
</QueryVal>
</RecAtt>
</ParentRec>
- <ErrMsg ErrNbr="0" ErrStat="MSG">
- <![CDATA[ Success
]]>
</ErrMsg>
</Report>
 
1) Go to 2) look up XML parser, you should find something there that'll float your boat

HTH
--Paul



Nancy Griffith - songstress extraordinaire,
and composer of the snipers anthem "From a distance ...
 
Although my parsing skills aren't beautiful I'd probably do something similar to the following:
Code:
# $src = the source you've posted

@CDATAS = split/\[CDATA/,$src;
foreach $CDATA (@CDATAS)  {
   ($CDATA,$etc) = split/\]\>/,$CDATA;
   if ($CDATA =~ /ASWTEST/i)  {
       print $CDATA."\n";
   }
}
It's nice and simple to understand that one I think...may not be necessary to get involved with a module if the info you need is as specific and simple as it is.

Rob Waite
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top