473,378 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

can not get rid of xml tags using Xpath

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>
Jul 20 '05 #1
2 1555
> 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,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #2
Thanks very much

Yang

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: bdinmstig | last post by:
I am building various framework components for my team to use in development, and one of those components is a Facade for reading/writing user preferences. The idea is that preference settings...
1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
1
by: John-Orr | last post by:
hi guys have a problem....... an XML problem basically my XML looks like this <heritage> <parent>343453 <parent>35634654 <parent>456456 <parent>456456 ..........loads more nested parent...
1
by: Philippe Poulard | last post by:
hi, People that are intersting in native XML programming can download the RefleX engine freely here : http://reflex.gforge.inria.fr RefleX is available under the french license CeCILL, which is...
3
by: Ward Bekker | last post by:
Hi, I need a regular expression that will match only the tags that have nested tags inside them: Input: <control id=1><control id=2></control></control><control id=3></control> Goal:
7
by: emferrari | last post by:
Hi all I have a XML file with the following: <Step step="1"> <Text><b>Chapter 1</b> This is a test. Click <b><i>Load</i></b> </Text> </Step>
10
by: Barry L. Camp | last post by:
Hi all... hope someone can help out. Not a unique situation, but my search for a solution has not yielded what I need yet. I'm trying to come up with a regular expression for a...
4
by: syed.akhlaq | last post by:
Hi, Does anyone know how can I validate XPath expressions using xsd schema? Thanks
12
by: minimalniemand | last post by:
I try to recursivley fill a treeview from a xml-file. It works well, when the contents of the xml and the treeview match 1:1. code here: http://mad-scientists.co.uk/micha/shownode.txt a sample...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.