R
reyesvsn
Hello everybody,
I have a question concerning XPath expressions and namespaces.
Consider this XML:
<?xml version="1.0" encoding="UTF-8"?>
<newsMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rtr="http://www.reuters.com/ns/2003/08/content"
xmlns="http://iptc.org/std/nar/2006-10-01/">
<header>
<transmitId>LWN_2008-07-26_892</transmitId>
<priority>4</priority>
<channel>VID</channel>
</header>
<itemSet>
<!-- ========================================================= -->
<!-- PRIMARY ITEM : NEP -->
<packageItem standard="NewsML-G2" standardversion="2.1"
conformance="power" guid="tag:reuters.com,2008:newsml_WNEI6QNH"
version="2" xml:lang="en">
<!-- ========================================================= -->
<itemMeta>
<itemClass qcode="icls:composite"/>
<versionCreated>2008-07-26T15:55:37Z</versionCreated>
<fileName>20080726954SP-FRANCE-EVIAN_GOLF.xml</fileName>
<link rel="irelrevVersion" residref="tag:reuters.com,
2008:newsml_WNEI6QNH" version="1" contenttype="application/
vnd.iptc.g2.packageitem+xml" rtr:id="WNEI6QNH" rtr:type="idType:USN"/>
<rtr:versionedId guid="tag:reuters.com,2008:newsml_WNEI6QNH:2"/>
</itemMeta>
</packageItem>
<!-- ========================================================= -->
<!-- PRIMARY ITEM : SNI-Text -->
<newsItem standard="NewsML-G2" standardversion="2.1"
conformance="power" guid="tag:reuters.com,2008:newsml_WNEI6QNI"
version="2" xml:lang="en">
<itemMeta>
<itemClass qcode="icls:text"/>
<versionCreated>2008-07-26T15:55:37Z</versionCreated>
<fileName>20080726954SP-FRANCE-EVIAN_GOLF.xml</fileName>
<link rel="irelrevVersion" residref="tag:reuters.com,
2008:newsml_WNEI6QNI" version="1" contenttype="application/
vnd.iptc.g2.newsitem+xml" rtr:id="WNEI6QNI" rtr:type="idType:USN"/>
<rtr:versionedId guid="tag:reuters.com,2008:newsml_WNEI6QNI:2"/>
</itemMeta>
</newsItem>
<!-- ========================================================= -->
<!-- PRIMARY ITEM : SNI -Video -->
<newsItem standard="NewsML-G2" standardversion="2.1"
conformance="power" guid="tag:reuters.com,2008:newsml_LWNEI6Q1CDHNJ"
version="1" xml:lang="en">
<itemMeta>
<itemClass qcode="icls:video"/>
<versionCreated>2008-07-26T15:55:37Z</versionCreated>
<rtr:versionedId guid="tag:reuters.com,2008:newsml_LWNEI6Q1CDHNJ:
1"/>
</itemMeta>
</newsItem>
</itemSet>
</newsMessage>
If the "newsMessage" node has the three namespaces (xmlns:xsi,
xmlns:rtr & xmlns), my XPath expressions like '/newsMessage/header/
priority/text()' returns nothing. But if I delete the third namespace
(xmlns), all my XPath expressions find the nodes and return the text
content except the expression '/newsMessage/itemSet/packageItem/
itemMeta/rtr:versionedId/@guid' that returns the error: 'Reference to
undeclared namespace prefix: 'rtr'.'
Any ideas about the problem?
Best regards
Reyes
I have a question concerning XPath expressions and namespaces.
Consider this XML:
<?xml version="1.0" encoding="UTF-8"?>
<newsMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rtr="http://www.reuters.com/ns/2003/08/content"
xmlns="http://iptc.org/std/nar/2006-10-01/">
<header>
<transmitId>LWN_2008-07-26_892</transmitId>
<priority>4</priority>
<channel>VID</channel>
</header>
<itemSet>
<!-- ========================================================= -->
<!-- PRIMARY ITEM : NEP -->
<packageItem standard="NewsML-G2" standardversion="2.1"
conformance="power" guid="tag:reuters.com,2008:newsml_WNEI6QNH"
version="2" xml:lang="en">
<!-- ========================================================= -->
<itemMeta>
<itemClass qcode="icls:composite"/>
<versionCreated>2008-07-26T15:55:37Z</versionCreated>
<fileName>20080726954SP-FRANCE-EVIAN_GOLF.xml</fileName>
<link rel="irelrevVersion" residref="tag:reuters.com,
2008:newsml_WNEI6QNH" version="1" contenttype="application/
vnd.iptc.g2.packageitem+xml" rtr:id="WNEI6QNH" rtr:type="idType:USN"/>
<rtr:versionedId guid="tag:reuters.com,2008:newsml_WNEI6QNH:2"/>
</itemMeta>
</packageItem>
<!-- ========================================================= -->
<!-- PRIMARY ITEM : SNI-Text -->
<newsItem standard="NewsML-G2" standardversion="2.1"
conformance="power" guid="tag:reuters.com,2008:newsml_WNEI6QNI"
version="2" xml:lang="en">
<itemMeta>
<itemClass qcode="icls:text"/>
<versionCreated>2008-07-26T15:55:37Z</versionCreated>
<fileName>20080726954SP-FRANCE-EVIAN_GOLF.xml</fileName>
<link rel="irelrevVersion" residref="tag:reuters.com,
2008:newsml_WNEI6QNI" version="1" contenttype="application/
vnd.iptc.g2.newsitem+xml" rtr:id="WNEI6QNI" rtr:type="idType:USN"/>
<rtr:versionedId guid="tag:reuters.com,2008:newsml_WNEI6QNI:2"/>
</itemMeta>
</newsItem>
<!-- ========================================================= -->
<!-- PRIMARY ITEM : SNI -Video -->
<newsItem standard="NewsML-G2" standardversion="2.1"
conformance="power" guid="tag:reuters.com,2008:newsml_LWNEI6Q1CDHNJ"
version="1" xml:lang="en">
<itemMeta>
<itemClass qcode="icls:video"/>
<versionCreated>2008-07-26T15:55:37Z</versionCreated>
<rtr:versionedId guid="tag:reuters.com,2008:newsml_LWNEI6Q1CDHNJ:
1"/>
</itemMeta>
</newsItem>
</itemSet>
</newsMessage>
If the "newsMessage" node has the three namespaces (xmlns:xsi,
xmlns:rtr & xmlns), my XPath expressions like '/newsMessage/header/
priority/text()' returns nothing. But if I delete the third namespace
(xmlns), all my XPath expressions find the nodes and return the text
content except the expression '/newsMessage/itemSet/packageItem/
itemMeta/rtr:versionedId/@guid' that returns the error: 'Reference to
undeclared namespace prefix: 'rtr'.'
Any ideas about the problem?
Best regards
Reyes