473,699 Members | 2,566 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 1788
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
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,...
1
2582
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
1922
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
2758
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
2159
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
5490
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
4975
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
4183
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
3548
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
9173
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
9033
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
8911
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
7748
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
6533
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
5872
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
4627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2345
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
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.