Pattern matching

  • Thread starter Deepan Perl XML Parser
  • Start date
D

Deepan Perl XML Parser

Hi all,
I am having a file like below:

<?xml version="1.0" encoding="UTF-8"?>
<log xmlns="http://www.httpwatch.com/xml/log/5.1">
<entry method="GET" URL="http://www.google.com/sa/frame_main.cgi">
..
..
..
..
-------some text-------------
..
..
..
</entry>
<entry method="GET" URL="http://www.toogle.com/framer/main.cgi">
..
..
..
..
-------some text-------------
..
..
..
</entry>
<entry method="GET" URL="http://www.google.com/sa/frame_main.html">
..
..
..
..
-------some text-------------
..
..
..
</entry>
<page id="page_0" title="Sustaining Portal" dynamic="true"
unknown="false">
<started>00:00:00.000</started>
<startedDateTime>2008-03-25T09:52:12.791</startedDateTime>
</page>
<page id="page_1" title="Sustaining Portal" dynamic="true"
unknown="false">
<started>00:00:08.455</started>
<startedDateTime>2008-03-25T09:52:21.246</startedDateTime>
</page>
<page id="page_2" title="Sustaining Portal" dynamic="true"
unknown="false">
<started>00:00:20.296</started>
<startedDateTime>2008-03-25T09:52:33.087</startedDateTime>
</page>
<page id="page_3" title="Sustaining Portal" dynamic="true"
unknown="false">
<started>00:00:29.848</started>
<startedDateTime>2008-03-25T09:52:42.639</startedDateTime>
</page>
</log>

----------------------------------------------------------------------------------

Now how to get all those <entry ....> tags into an array? I mean
getting

<entry method="GET" URL="http://www.google.com/sa/
frame_main.cgi">
<entry method="GET" URL="http://www.toogle.com/framer/
main.cgi">
<entry method="GET" URL="http://www.google.com/sa/
frame_main.html">

into some array.

Thanks,
Deepan
 
D

Deepan Perl XML Parser

Hi all,
I am having a file like below:

<?xml version="1.0" encoding="UTF-8"?>
<log xmlns="http://www.httpwatch.com/xml/log/5.1">
<entry method="GET" URL="http://www.google.com/sa/frame_main.cgi">
.
.
.
.
-------some text-------------
.
.
.
</entry>
<entry method="GET" URL="http://www.toogle.com/framer/main.cgi">
.
.
.
.
-------some text-------------
.
.
.
</entry>
<entry method="GET" URL="http://www.google.com/sa/frame_main.html">
.
.
.
.
-------some text-------------
.
.
.
</entry>
<page id="page_0" title="Sustaining Portal" dynamic="true"
unknown="false">
<started>00:00:00.000</started>
<startedDateTime>2008-03-25T09:52:12.791</startedDateTime>
</page>
<page id="page_1" title="Sustaining Portal" dynamic="true"
unknown="false">
<started>00:00:08.455</started>
<startedDateTime>2008-03-25T09:52:21.246</startedDateTime>
</page>
<page id="page_2" title="Sustaining Portal" dynamic="true"
unknown="false">
<started>00:00:20.296</started>
<startedDateTime>2008-03-25T09:52:33.087</startedDateTime>
</page>
<page id="page_3" title="Sustaining Portal" dynamic="true"
unknown="false">
<started>00:00:29.848</started>
<startedDateTime>2008-03-25T09:52:42.639</startedDateTime>
</page>
</log>

----------------------------------------------------------------------------------

Now how to get all those <entry ....> tags into an array? I mean
getting

<entry method="GET" URL="http://www.google.com/sa/
frame_main.cgi">
<entry method="GET" URL="http://www.toogle.com/framer/
main.cgi">
<entry method="GET" URL="http://www.google.com/sa/
frame_main.html">

into some array.

Thanks,
Deepan

while($string =~ m#<entry method=.* URL="http://(.*)">#g)
{
..................
..................
}

I am able to do this by using the above expr. Is there any fair way of
doing it other than this?
 
J

Jürgen Exner

Deepan Perl XML Parser said:
I am having a file like below:
<?xml version="1.0" encoding="UTF-8"?> [...]
Now how to get all those <entry ....> tags into an array? I mean

You would use an XML parser to parse XML.
Has nothing to do with pattern matching at all.

jue
 
D

Deepan Perl XML Parser

Deepan Perl XML Parser said:
I am having a file like below:
<?xml version="1.0" encoding="UTF-8"?> [...]
Now how to get all those <entry ....> tags into an array? I mean

You would use an XML parser to parse XML.
Has nothing to do with pattern matching at all.

jue

No i am writing my own XML parser.
 
D

Deepan Perl XML Parser

Don't. There are many good XML parsers out there, the world doesn't
need another one.

--
Lawrence Statton - (e-mail address removed) s/aba/c/g
Computer software consists of only two components: ones and
zeros, in roughly equal proportions. All that is required is to
place them into the correct order.

Okay then can you name any parsers that would get the CDATA section?
 
P

Peter J. Holzer

Okay then can you name any parsers that would get the CDATA section?

Which one doesn't?

LibXML certainly does (I just tested it). I think expat does, too.
I have my doubts about the pure perl XML parser, but that has a lot of
other problems too and shouldn't be used.

hp
 
D

Deepan Perl XML Parser

Which one doesn't?

LibXML certainly does (I just tested it). I think expat does, too.
I have my doubts about the pure perl XML parser, but that has a lot of
other problems too and shouldn't be used.

hp

This one XML::parser doesn't. It just signals you as CDATA starts and
ends here. It is not possible to get the data which is present using
this.
 
P

Peter J. Holzer

This one XML::parser doesn't. It just signals you as CDATA starts and
ends here. It is not possible to get the data which is present using
this.

Works for me:

chronos:/wsrdb/users/hjp/tmp 20:47 112% cat foo.xml
<script>
<![CDATA[
function matchwo(a,b)
{
if (a < b && a < 0) then
{
return 1;
}
else
{
return 0;
}
}
]]>
</script>
chronos:/wsrdb/users/hjp/tmp 20:47 113% cat foo
#!/usr/bin/perl
use XML::Simple;
use Data::Dumper;

$x = XMLin($ARGV[0]);
print Dumper $x;
chronos:/wsrdb/users/hjp/tmp 20:47 114% export XML_SIMPLE_PREFERRED_PARSER=XML::parser
chronos:/wsrdb/users/hjp/tmp 20:47 115% ./foo foo.xml
$VAR1 = '

function matchwo(a,b)
{
if (a < b && a < 0) then
{
return 1;
}
else
{
return 0;
}
}

';

hp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top