473,705 Members | 5,086 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with XML/XPATH

Hi,
I have the following XML:-

<X1>
<Props>
<Prop xsi:type=\"text \" Name=\"N1\"><Va lue>TestUser</Value></Prop>
<Prop xsi:type=\"bool \" Name=\"flag\">< Value>0</Value></Prop>
<Prop xsi:type=\"int\ " Name=\"numemp\" ><Value>100</Value></Prop>
</Props>
</X1>
I want to extract just the value for a specific <Prop>, for instance I
want to be able to just retrieve the Value of the "flag" <Prop>.
I am thinking of looping through each node and testing for the Name
attribute but that seems a little complicated. Is there a way to do it
using XPATH?

Any help?

Thanks

Nov 12 '05 #1
3 1265
Dan
First, I'm assuming your XML looks like this, since what you posted is nt
well-formed:
<X1>
<Props>
<Prop xsi:type="text" Name="N1"><Valu e>TestUser</Value></Prop>
<Prop xsi:type="bool" Name="flag"><Va lue>0</Value></Prop>
<Prop xsi:type="int" Name="numemp">< Value>100</Value></Prop>
</Props>
</X1>

To get at the value, the xpath is something like:
/X1/Props/Prop[@Name='flag']/Value

The flage value can be input as a variable into the XPATH:
<xsl:variable name="input">fl ag</xsl:variable>
<xsl:value-of select="/X1/Props/Prop[@Name=$input]/Value"/>

dan
"baggy" <gb******@hotma il.com> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.com...
Hi,
I have the following XML:-

<X1>
<Props>
<Prop xsi:type=\"text \" Name=\"N1\"><Va lue>TestUser</Value></Prop>
<Prop xsi:type=\"bool \" Name=\"flag\">< Value>0</Value></Prop>
<Prop xsi:type=\"int\ " Name=\"numemp\" ><Value>100</Value></Prop>
</Props>
</X1>
I want to extract just the value for a specific <Prop>, for instance I
want to be able to just retrieve the Value of the "flag" <Prop>.
I am thinking of looping through each node and testing for the Name
attribute but that seems a little complicated. Is there a way to do it
using XPATH?

Any help?

Thanks

Nov 12 '05 #2
In <comp.text.xm l> baggy <gb******@hotma il.com> wrote:
Hi,
I have the following XML:-

<X1>
<Props>
<Prop xsi:type=\"text \" Name=\"N1\"><Va lue>TestUser</Value></Prop>
<Prop xsi:type=\"bool \" Name=\"flag\">< Value>0</Value></Prop>
<Prop xsi:type=\"int\ " Name=\"numemp\" ><Value>100</Value></Prop>
</Props>
</X1>
I want to extract just the value for a specific <Prop>, for instance I
want to be able to just retrieve the Value of the "flag" <Prop>. I am
thinking of looping through each node and testing for the Name
attribute but that seems a little complicated. Is there a way to do it
using XPATH?

Any help?


First, fix the quoting of double-quotes. Once you have
<X1>
<Props>
<Prop xsi:type="text" Name="N1"><Valu e>TestUser</Value></Prop>
<Prop xsi:type="bool" Name="flag"><Va lue>0</Value></Prop>
<Prop xsi:type="int" Name="numemp">< Value>100</Value></Prop>
</Props>
</X1>
then feed it through Bash shell with Expat interface. Something like

start() # Usage: start tag type=bool Name=flag ...
{
case $1 in
Value) unset value ;;
esac
}
data() # Usage: data text
{
case ${XML_ELEMENT_S TACK[1]} in
Value) strcat value "$1" ;;
esac
}
end() # Usage: end tag
{
case $1 in
Value) [ "${XML_ELEMENT_ STACK|=Name=fla g}" ] && echo "Value=$val ue" ;;
easc
}
expat -s start -d data -e end < file.xml

--
William Park <op**********@y ahoo.ca>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
http://freshmeat.net/projects/bashdiff/
Nov 12 '05 #3
sure, but like they said clean up your XML

<X1>
<Props>
<Prop xsi:type="text" Name="N1"><Valu e>TestUser</Value></Prop>
<Prop xsi:type="bool" Name="flag"><Va lue>0</Value></Prop>
<Prop xsi:type="int" Name="numemp">< Value>100</Value></Prop>
</Props>
</X1>

using XSL, you can use something like:

<xsl:value-of select="//Prop[@Name='flag'" />

I don't know what the full XML looks like so...

Nov 12 '05 #4

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

Similar topics

4
6345
by: MegaZone | last post by:
I'm having some issues with PHP DOMXML - in particular the get_elements_by_tagname method. Now, the PGP docs on this are, well, sparse, so maybe I'm just doing something stupid. I thought this method would behave like the 'findnodes' XML method in Perl. Namely that you can pass it an xpath statement and it will find nodes that match: $array = $node->get_elements_by_tagname($xpath); This is long so here's a pagebreak: And, indeed,...
0
1927
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context import Context import xml.xpath
3
2409
by: Thierry Lam | last post by:
Let's say I have the following xml tag: <para role="success">1</para> I can't figure out what kind of python xml.dom codes I should invoke to read the data 1? Any help please? Thanks Thierry
0
1724
by: Rajesh Jain | last post by:
I Have 2 separate schemas. --------------Schema 1 is defined as below----------- <xs:schema targetNamespace="http://Schemas/1" xmlns="http://Schemas/1" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="Loan"> <xs:complexType> <xs:sequence> <xs:element name="Borrower" maxOccurs="unbounded"> <xs:complexType> <xs:attribute name="BorrID" use="required">
4
2501
by: Iain A. Mcleod | last post by:
Hi I'm stuck with the following schema validation problem in VS.NET 2003: I have two types of xml document and related schema: project and projectCollection. A projectcollection is just a set of projects. Therefore, I wish to include the project customType in the projectCollection namespace. I therefore have declared two xsd documents: project.xsd and projectcollection.xsd
6
15508
by: Chua Wen Ching | last post by:
Hi there, I had this xml file with me (not yet consider implementing xml namespaces yet). <?xml version='1.0'?> <Object> <Windows> <EID>1</EID> <EDesc>Error 1</EDesc> </Windows>
3
1287
by: John Lee | last post by:
Hi, I have a document <root> <name>John</name> </root> and the xpath "//name" will return correct node by using xmldoc.SelectSingleNode(xpath) and if the document contains a default namespace
7
1263
by: Peter Morris [Droopy eyes software] | last post by:
Hi all I need a little help with XSD, here is my XML <data> <brandData> <brandGroups> <brandGroup> <name>Group1</name> </brandGroup>
1
416
by: Showjumper | last post by:
Hi, I need some help with xpath. I am very unfamilair with XPATH. I have an xml file with the folloing structure: <Photos> <Photo> <Description>This is a photo of horse that colicked. The bowel is necrotic and on the wrong side of the horse. </Description> <FileName>deadbowel.jpg</FileName> <FilePath>/photos/Pathology/deadbowel.jpg</FilePath> </Photo>
2
1791
by: Monty | last post by:
Despite reading posts in Google, I don't understand XPATH. Can someone help me write an XPATH. From Google I think my problem is that the default namespace does not have a prefix. I can't change this as I have received this XML and I didn't create it. All I want to is retrieve the PROJECTNAME from the following XML. I am typing this XML and XPATH into this site http://www.activsoftware.com/xml/xpath/ The XPATH that does not work is...
0
8768
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8690
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9034
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7895
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3138
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2083
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.