can not get rid of xml tags using Xpath

Yang (archive)

Usenet Archive
Joined
Aug 5, 2003
Messages
21
Reaction score
0
Hi everyone:

after I parse a .xml file, I still have the xml tags in my varibles. Please help. Why my $title varible is " <title>title is here</title>" instead of "title is here"???

thanks very much

Yang

Here is the code:
################################## test.pl ###################### #! /usr/bin/perl my $infile = "test8.xml"; my ($title, $message); use XML::XPath; use XML::XPath::XMLParser; my $xp = XML::XPath->new( filename => $infile );

my $titles = $xp->find('//david3/title');
foreach my $title1 ($titles->get_nodelist) {
$title = XML::XPath::XMLParser::as_string($title1);
}

my $messages = $xp->find('/david3/message');
foreach my $message1 ($messages->get_nodelist) {
$message = XML::XPath::XMLParser::as_string($message1); } print "title: $title\n"; print "message: $message\n"; ##################################################################

Here is my input file
####################### test8.xml ################################# <?xml version="1.0"?> <david3 template="/Templates/david3.dwt" codeOutsideHTMLIsLocked="false"> <message>message is here</message> <title>title is here</title> </david3> #################################################################

Here is the result of running test.pl test8.xml
title: <title>title is here</title>
message: <message>message is here</message>
 

Joris Gillis

Usenet Archive
Joined
Sep 28, 2004
Messages
355
Reaction score
0
after I parse a .xml file, I still have the xml tags in my varibles.
Please help. Why my $title varible is " <title>title is here</title>"

$title = XML::XPath::XMLParser::as_string($title1);
Hi,

I think you could use:
$title = $title1->string_value;

regards,
 

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
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top