473,508 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading Xpath element

Hi Teacher.

I'm trying to get with Xpath the Product nodes in the following XML:
<?xml version="1.0" encoding="utf-8"?>
<PLMXML xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema"
schemaVersion="5.1" date="2005-05-03" time="16:41:33" author="TcEng -
infodba@bridge(389284449)">
<Header id="id1" traverseRootRefs="#id2 #id11"
transferContext="exp_folder"></Header>
<Product id="id10" name="Ace" accessRefs="#id3" subType="Drawing"
productId="000002">
<ApplicationRef version="QRJJ3Vh1xNEIWA" application="TcEng"
label="QRJJ3Vh1xNEIWA"></ApplicationRef>
<UserData id="id33">
<UserValue type="reference" value="" title="owning_user"
dataRef="#id11"></UserValue>
<UserValue value="0-01-00T00:00:00" title="date_released"></UserValue>
<UserValue value="2005-05-03T14:00:32"
title="last_mod_date"></UserValue>
<UserValue type="reference" value="" title="last_mod_user"
dataRef="#id11"></UserValue>
<UserValue type="reference" value="" title="owning_group"
dataRef="#id27"></UserValue>
<UserValue value="2005-05-03T10:46:39"
title="creation_date"></UserValue></UserData></Product> (Continue...)

I've used the /PLMXML/Product query but I can't get anything.

I've also tried this simple xml:
<?xml version='1.0'?>
<Books>
<Book>
<Title>Beginning XML</Title>
<Publisher>Wrox</Publisher>
</Book>
<Book>
<Title>XML Step by Step</Title>
<Publisher>MSPress</Publisher>
</Book>
<Book>
<Title>Professional XML</Title>
<Publisher>Wrox</Publisher>
</Book>
<Book>
<Title>Developing XML solutions</Title>
<Publisher>MSPress</Publisher>
</Book>
</Books>

And on this Xml the rule /Books/Book works fine.

Why does not the first rule work?
Am I missing something?

Thanks in advance.
Marco.

Jul 20 '05 #1
4 3023
Ma******@gmail.com wrote:
Hi Teacher.

I'm trying to get with Xpath the Product nodes in the following XML:
<?xml version="1.0" encoding="utf-8"?>
<PLMXML xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema"
schemaVersion="5.1" date="2005-05-03" time="16:41:33" author="TcEng -
infodba@bridge(389284449)">
<Header id="id1" traverseRootRefs="#id2 #id11"
transferContext="exp_folder"></Header>
<Product id="id10" name="Ace" accessRefs="#id3" subType="Drawing"
productId="000002">
<ApplicationRef version="QRJJ3Vh1xNEIWA" application="TcEng"
label="QRJJ3Vh1xNEIWA"></ApplicationRef>
<UserData id="id33">
<UserValue type="reference" value="" title="owning_user"
dataRef="#id11"></UserValue>
<UserValue value="0-01-00T00:00:00" title="date_released"></UserValue>
<UserValue value="2005-05-03T14:00:32"
title="last_mod_date"></UserValue>
<UserValue type="reference" value="" title="last_mod_user"
dataRef="#id11"></UserValue>
<UserValue type="reference" value="" title="owning_group"
dataRef="#id27"></UserValue>
<UserValue value="2005-05-03T10:46:39"
title="creation_date"></UserValue></UserData></Product> (Continue...)

I've used the /PLMXML/Product query but I can't get anything.
with XPath, unprefixed elements refers to elements that are not bound to
a namespace URI ; in XML, unprefixed elements may be bound to a
namespace URI ; this is the case in the document above, and not the case
in the document below
thus, /PLMXML gets the PLMXML element with no namespace URI, that
doesn't appear anywhere ; to get the PLMXML element bound to this
namespace URI "http://www.plmxml.org/Schemas/PLMXMLSchema", you must
declare a mapping between a prefix and the namespace URI :
plm -> "http://www.plmxml.org/Schemas/PLMXMLSchema"
and then use it in your XPath expression :
/plm:PLMXML/plm:Product
how to declare the mapping vary according to the XPath engine you use,
but people usually use it with XSLT ; with XSLT, namespaces declarations
are used by the XPath engine

I've also tried this simple xml:
<?xml version='1.0'?>
<Books>
<Book>
<Title>Beginning XML</Title>
<Publisher>Wrox</Publisher>
</Book>
<Book>
<Title>XML Step by Step</Title>
<Publisher>MSPress</Publisher>
</Book>
<Book>
<Title>Professional XML</Title>
<Publisher>Wrox</Publisher>
</Book>
<Book>
<Title>Developing XML solutions</Title>
<Publisher>MSPress</Publisher>
</Book>
</Books>

And on this Xml the rule /Books/Book works fine.

Why does not the first rule work?
Am I missing something?

Thanks in advance.
Marco.

--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------
Jul 20 '05 #2


Ma******@gmail.com wrote:

I'm trying to get with Xpath the Product nodes in the following XML:
<?xml version="1.0" encoding="utf-8"?>
<PLMXML xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema"
schemaVersion="5.1" date="2005-05-03" time="16:41:33" author="TcEng -
infodba@bridge(389284449)"> I've used the /PLMXML/Product query but I can't get anything.


See
<http://www.faqts.com/knowledge_base/view.phtml/aid/34022/fid/616>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #3
Thanks guys!

I'm using libxml2 libraries from C, and I solved the problem matching
nodes with name and namespace-uri attributes because I can't control
the xml format.

Jul 20 '05 #4

This is a FAQ (you may want to see the xsl-list faq at
www.dpawson.co.uk)
<PLMXML xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema"

That is an element with local name PLMXML and namespace http://www.plmxml.org/Schemas/PLMXMLSchema

I've used the /PLMXML/Product

That matches elements PLMXML and Product in no-namespace.

Add

xmlns:p="http://www.plmxml.org/Schemas/PLMXMLSchema"

to your xsl:stylesheet element and then use

/p:PLMXML/p:Product

To match elements in this namespace.

David
Jul 20 '05 #5

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

Similar topics

1
6812
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...
8
5089
by: Lawrence Oluyede | last post by:
Is there a way to treat html tags like simple text? I explain myself, if I have a bunch of xml like <content type="application/xhtml+xml" xml:base="http://loluyede.blogspot.com" xml:lang="en-US"...
1
3013
by: Hollywood | last post by:
I have the following XSD created in VS.NET 2003: <?xml version="1.0" encoding="utf-8" ?> <xs:schema id="ReferralSchama" targetNamespace="http://test.org/Referral"...
1
1248
by: Ganesh Muthuvelu | last post by:
Hello, Let us say I have a schema file like this sample below. How would I using ..NET classes be able to read this XSD file and get all the values for each element, such as "name", "type",...
1
1661
by: paul_zaoldyeck | last post by:
Good Day everyone!!! i have here a serious problem.my project is delayed because of this. i'm trying to make a function for an XML Reader that accepts values from the other modules(done by the...
11
6085
by: J_Zanetti | last post by:
Hello everybody, In my applications I've a ton of scripts that use remote XML file to fill forms and evaluate contents; In these scripts I always use the method SelectNode (that, with some...
8
6771
by: BiT | last post by:
Hello i'm tryin` to read xml elements from NZB type file (Link to nzb sample: http://en.wikipedia.org/wiki/Nzb) I worte this code but it dosen't find any elements (I need to get the message...
0
7135
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...
0
7342
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,...
0
7410
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...
0
5650
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,...
1
5060
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...
0
4729
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...
0
3215
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...
0
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
440
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...

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.