Y
Yang
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>
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>