473,836 Members | 1,514 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with simple XPATH

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 /PROJECTS/PROJECTNAME.

Thank you
Monty

<PROJECTS xmlns="http://www.companyname .com/project"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance">
<PROJECTNAME>
Project A
</PROJECTNAME>
<PROJECTBUDGE T>
27000
</PROJECTBUDGET>
</PROJECTS>

Dec 30 '06 #1
2 1793
Monty wrote:
The XPATH that does not work is /PROJECTS/PROJECTNAME.
<PROJECTS xmlns="http://www.companyname .com/project"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance">
<PROJECTNAME>
Project A
</PROJECTNAME>

Those elements are in the namespace http://www.companyname.com/project
so for XPath to qualify element names in your expression you need to
bind a prefix to the namespace URI. Check your XPath API on how to do
that exactly, you can choose any prefix you like and you don't have to
change the XML source document, you just need to make sure your XPath
API knows that e.g. 'pf' is bound to http://www.companyname.com/project
and then you can use expressions alike
/pf:PROJECTS/pf:PROJECTNAME

Or as an alternative you could use e.g.
/*[namespace-uri() = 'http://www.companyname .com/project' and
local-name() = 'PROJECTS']/*[namespace-uri() =
'http://www.companyname .com/project' and local-name() = 'PROJECTNAME']
--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 30 '06 #2
Monty wrote:
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 /PROJECTS/PROJECTNAME.

Thank you
Monty

<PROJECTS xmlns="http://www.companyname .com/project"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance">
<PROJECTNAME>
Project A
</PROJECTNAME>
<PROJECTBUDGE T>
27000
</PROJECTBUDGET>
</PROJECTS>
You have to supply namespace prefixes in xsl/xpath for default
namespaces in xml. It took a bit of fussing, but here's a solution:

<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml" >
<xsl:template xmlns:pn="http://www.companyname .com/project" match="/">
<xsl:apply-templates select="pn:PROJ ECTS/pn:PROJECTNAME" />
<xsl:apply-templates select="pn:PROJ ECTS/pn:PROJECTBUDGE T" />
</xsl:template>

<xsl:template xmlns:pn="http://www.companyname .com/project"
match="pn:PROJE CTNAME">
Project Name: <xsl:value-of select = "." /><br />
</xsl:template>

<xsl:template xmlns:pn="http://www.companyname .com/project"
match="pn:PROJE CTBUDGET">
Budget: <xsl:value-of select = "." />
</xsl:template>

</xsl:stylesheet>

--

_______________ ______
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/
Jan 5 '07 #3

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

Similar topics

4
6354
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,...
1
2594
by: Joshua Beall | last post by:
Hi All, I have a task that should be very simple but I'm running into trouble. All I want to do is query a document using XPath, and save the resulting XML in a string. Here's that I am trying (PHP5): // $xml has the entire XML document in it; I included it for reference at the end of the document $dom = new DOMDocument(); $dom->loadXML($xml);
0
1933
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
2
2762
by: Jerry O | last post by:
Hi - I am stuck on what might be a simple Xpath expression, I just can't visualize the query. I have a node set that can be the child of any of three nodes. I would like to test if a node matching has the child <related_info type="x" />. Here's my XML
4
2163
by: gfrommer | last post by:
Hello everyone, I've been reading through a bunch of XPath tutorials and am confused by a couple items. First, is it possible to have multiple predicates in my XPath statement. For example, the following xpath statement: "//AAA/BBB/c" should only return the last <c> node containing the 6, correct? Also consider the statement "//AAA/BBB" returns the first two <BBB> items, correct? the and's and or's in the predicates are all right yes?
7
5499
by: Ot | last post by:
I posted this to the wrong group. It went to m.p.dotnet.languages.vb. Ooops. -------------------------------------------------------------------- I have this tiny problem. I have learned that an xpath expression can be bounded by either single or double quotation marks. But sometimes I want to search for a title containing both a single and double quote. Any way to do this?
3
4981
by: Jason Mobarak | last post by:
Hello -- I'm attempting to get a handle on how to do xpath queries with System.Xml -- so far the biggest hurdle has been how to deal with a default namespace. If I use the test xml: <?xml version="1.0" encoding="utf-8" ?> <thing xmlns="urn:thing-schema-v1"> <foo>foo thing</foo> <bar>bar thing</bar>
2
4190
by: eggie5 | last post by:
I know how to edit my page using xpath selectors in firefox, it's just like this (in the else if). However, I can't find any way to do it in IE? I just want to find all links with the className=='leftNavPElement' and then set them to 'leftNavBltItem', but I can't find how to do the xpath stuff in IE. Can somebody please fill in the if statment ie code for me? if (window.ActiveXObject) {
1
3553
by: Alexey Titov | last post by:
Hi :) I need help selecting particular nodes with the SelectChildren method I get a simple xml from the web (excerpt): <ab:store> <ab:goods> <ab:icecream> <ab:flavor_01>
0
9825
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
9671
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
10854
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10558
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...
0
10257
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
9387
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...
1
7794
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.