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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing of a Line in XML File

Status
Not open for further replies.

Ramnarayan

Programmer
Jan 15, 2003
56
US
Hi,

I have a xml file which has a part of the output as below:

<SD>
<DT>
lskdjflasd
lsdajflksdjf
sldkjflsadkjf
</DT>
<DS>XSD</DS>
</SD>
<SD>
<DT>
some text
here
and
there
</DT>
<DS>P</DS>
</SD>

Now I am trying to write a piece of software that should take the text such that wherever "<DS>XSD</DS> occurs, I should be able to get the # of characters of the entire block of text including the tag content from <SD>... </SD>. Note that for the second part of <SD>...</SD> where <DS> has "P" should not be calculated!

I am unable to figure out a logic on how this should be put in a if loop!. Is there any other way? Thanks for your help!
 
I would have a look at the module XML::parser which is in the standard distribution.

Mike

You cannot really appreciate Dilbert unless you've read it in the
original Klingon.

Want great answers to your Tek-Tips questions? Have a look at faq219-2884

 
First of all check the structure of the XML File (Valid XML format) Try open the file using IE.

Second use any of the XML Parsers already built like XML Parser, XML::Simple or XML Twig...BTW The structure of this XML File is quite simple.

Third, include the Module Data Dumper in order to see the XML structure..

Something like:

use strict;
use XML::Simple;
use Data::Dumper;

my $file = XMLin('c:\perl\examples\ric\xml\MYFILE.xml');
print Dumper($file);

dmazzini
GSM System and Telecomm Consultant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top