473,387 Members | 3,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

selecting specific elements with xpath


I've some problems with filtering out a specific element by the following
xml snippet (is part of a bigger xml document):

<entry>
<link href="http://www.blogger.com/atom/5281182/108809850419059234"
rel="service.edit" title="test" type="application/x.atom+xml"/>
<author>
<name>Lawrence</name>
</author>
<issued>2004-06-24T19:34:04+02:00</issued>
<modified>2004-06-24T17:35:04Z</modified>
<created>2004-06-24T17:35:04Z</created>
<link href="http://loluyede.blogspot.com/2004/06/test_24.html"
rel="alternate" title="test" type="text/html"/>
<id>tag:blogger.com,1999:blog-5281182.post-108809850419059234</id>
<title mode="escaped" type="text/html">test</title>
<content type="application/xhtml+xml"
xml:base="http://loluyede.blogspot.com" xml:lang="en-US"
xml:space="preserve">
<div xmlns="http://www.w3.org/1999/xhtml">this test is a post</div>
</content>
</entry>

The code I use is (assume that navigator is positioned on the <entry>
element):

XPathNavigator nav = navigator.Clone();
XPathNodeIterator iter = nav.SelectDescendants(XPathNodeType.Element,
true);

iter = nav.Select("//link[@type=\"text/html\" and @rel=\"alternate\"]");

and it returns me 0 nodes, instead if i copy and paste the above snippet in
a single document (so <entry> becomes the root) and open it with
XPathDocument the above code works, why?

--
Lawrence
"ain't nothin' but fun."
Nov 12 '05 #1
12 3459
Lawrence Oluyede wrote:
XPathNodeIterator iter = nav.SelectDescendants(XPathNodeType.Element,
true);

iter = nav.Select("//link[@type=\"text/html\" and @rel=\"alternate\"]");


That's sort of weird. You select descendants and then discarding the
variable, making another selection. What's the point of the
SelectDescendants() call?

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
Lawrence Oluyede wrote:
XPathNodeIterator iter = nav.SelectDescendants(XPathNodeType.Element,
true);

iter = nav.Select("//link[@type=\"text/html\" and @rel=\"alternate\"]");


That's sort of weird. You select descendants and then discarding the
variable, making another selection. What's the point of the
SelectDescendants() call?

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #3
In data Sun, 27 Jun 2004 14:29:35 +0200, Oleg Tkachenko [MVP] ha scritto:
That's sort of weird. You select descendants and then discarding the
variable, making another selection. What's the point of the
SelectDescendants() call?


Yeah you're right but removing that call doesn't solve the problem :(

--
Lawrence
"ain't nothin' but fun."
Nov 12 '05 #4
In data Sun, 27 Jun 2004 14:29:35 +0200, Oleg Tkachenko [MVP] ha scritto:
That's sort of weird. You select descendants and then discarding the
variable, making another selection. What's the point of the
SelectDescendants() call?


Yeah you're right but removing that call doesn't solve the problem :(

--
Lawrence
"ain't nothin' but fun."
Nov 12 '05 #5
Lawrence Oluyede wrote:
iter = nav.Select("//link[@type=\"text/html\" and @rel=\"alternate\"]");

and it returns me 0 nodes, instead if i copy and paste the above snippet in
a single document (so <entry> becomes the root) and open it with
XPathDocument the above code works, why?


Chances are you've got namespaces involved. Show us entry ancestors.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #6
Lawrence Oluyede wrote:
iter = nav.Select("//link[@type=\"text/html\" and @rel=\"alternate\"]");

and it returns me 0 nodes, instead if i copy and paste the above snippet in
a single document (so <entry> becomes the root) and open it with
XPathDocument the above code works, why?


Chances are you've got namespaces involved. Show us entry ancestors.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #7
In data Sun, 27 Jun 2004 15:08:52 +0200, Oleg Tkachenko [MVP] ha scritto:
Chances are you've got namespaces involved. Show us entry ancestors.


The file is http://loluyede.blogspot.com/atom.xml

Thanks!

--
Lawrence
" It's probably for the best. What use does Microsoft have for an employee
who knows the W3C standards?"
-- an anonymous about tantek departure from microsoft
Nov 12 '05 #8
In data Sun, 27 Jun 2004 15:08:52 +0200, Oleg Tkachenko [MVP] ha scritto:
Chances are you've got namespaces involved. Show us entry ancestors.


The file is http://loluyede.blogspot.com/atom.xml

Thanks!

--
Lawrence
" It's probably for the best. What use does Microsoft have for an employee
who knows the W3C standards?"
-- an anonymous about tantek departure from microsoft
Nov 12 '05 #9
Lawrence Oluyede wrote:
Chances are you've got namespaces involved. Show us entry ancestors.

The file is http://loluyede.blogspot.com/atom.xml


Yeah, I was right. Look at this:

<feed version="0.3" xmlns="http://purl.org/atom/ns#">

That xmlns="http://purl.org/atom/ns#" is default namespace declaration.
That means feed element and all its descendants elements are in
"http://purl.org/atom/ns#" namespace.

Read about default namespace and XPath (there was good article at
Extreme XML column a couple of years ago) and take a look at
XPathNavigator.Select(XPathExpression) method documentation for a sample
of selecting nodes with default namespace involved.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #10
Lawrence Oluyede wrote:
Chances are you've got namespaces involved. Show us entry ancestors.

The file is http://loluyede.blogspot.com/atom.xml


Yeah, I was right. Look at this:

<feed version="0.3" xmlns="http://purl.org/atom/ns#">

That xmlns="http://purl.org/atom/ns#" is default namespace declaration.
That means feed element and all its descendants elements are in
"http://purl.org/atom/ns#" namespace.

Read about default namespace and XPath (there was good article at
Extreme XML column a couple of years ago) and take a look at
XPathNavigator.Select(XPathExpression) method documentation for a sample
of selecting nodes with default namespace involved.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #11
In data Sun, 27 Jun 2004 18:19:37 +0200, Oleg Tkachenko [MVP] ha scritto:
Yeah, I was right. Look at this:

<feed version="0.3" xmlns="http://purl.org/atom/ns#">
Yeah I did know because I've added namespace capability for the parsing
object model, maybe that part doesn't recognize the namespace declaration
That xmlns="http://purl.org/atom/ns#" is default namespace declaration.
That means feed element and all its descendants elements are in
"http://purl.org/atom/ns#" namespace.
Right
Read about default namespace and XPath (there was good article at
Extreme XML column a couple of years ago)
I know, I've read it sometimes ago
and take a look at
XPathNavigator.Select(XPathExpression) method documentation for a sample
of selecting nodes with default namespace involved.


I try to "wire in" the namespace declaration, thanks!

--
Lawrence
" It's probably for the best. What use does Microsoft have for an employee
who knows the W3C standards?"
-- an anonymous about tantek departure from microsoft
Nov 12 '05 #12
In data Sun, 27 Jun 2004 18:19:37 +0200, Oleg Tkachenko [MVP] ha scritto:
Yeah, I was right. Look at this:

<feed version="0.3" xmlns="http://purl.org/atom/ns#">
Yeah I did know because I've added namespace capability for the parsing
object model, maybe that part doesn't recognize the namespace declaration
That xmlns="http://purl.org/atom/ns#" is default namespace declaration.
That means feed element and all its descendants elements are in
"http://purl.org/atom/ns#" namespace.
Right
Read about default namespace and XPath (there was good article at
Extreme XML column a couple of years ago)
I know, I've read it sometimes ago
and take a look at
XPathNavigator.Select(XPathExpression) method documentation for a sample
of selecting nodes with default namespace involved.


I try to "wire in" the namespace declaration, thanks!

--
Lawrence
" It's probably for the best. What use does Microsoft have for an employee
who knows the W3C standards?"
-- an anonymous about tantek departure from microsoft
Nov 12 '05 #13

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

Similar topics

1
by: Alastair Cameron | last post by:
VB6, MSXML 3.2 installed: Q1. I am having a problem selecting nodes with XPATH expressions when an attribute values contain backslashes (\\) in as part of its value: For example the...
2
by: thomas | last post by:
Hello all Im having problems with selecting subelements from a dynamic created RTF converted to a node-set: i have hardcodet this example: the xml structure: <xsl:variable name="test">
2
by: Mike Kamermans | last post by:
I'm having some trouble using text() in an xsl:value-of xpath. I have the following xml: .... <graphemes> <grapheme>1</grapheme> <grapheme>2</grapheme> <grapheme>3</grapheme> </graphemes>...
9
by: Tjerk Wolterink | last post by:
Hello, suppose i have a dom like this: <a> - <b> - <b> - <d> - </b> - <c>
1
by: Marek Mänd | last post by:
<style> .marek{} </style> etc.. <root> <element class="marek mand"/> <element class="mand marek blah"/> <element class="mand marekmänd"/> <element class="mand marekk"/> </root>
0
by: Lawrence Oluyede | last post by:
I've some problems with filtering out a specific element by the following xml snippet (is part of a bigger xml document): <entry> <link...
0
by: Kent Boogaart | last post by:
Hi, Suppose an XSD as follows: <xsd:complexType name="myType"> <xsd:complexContent> <xsd:extension base="myBaseType"> <xsd:sequence> <xsd:element name="thing" minOccurs="0"...
7
by: Thomas Schmidt | last post by:
Hi all, I need an XPath which selects all nodes of a specific name which start with a text node, i.e. I want the expression to select: <x> abcdefg <y>hijklmn</y> </x>
11
by: Michael Bray | last post by:
I'm playing around with XElement stuff, and I've come across a difficulty. The XML document that I'm reading contains an xmlns declaration on the main node... <root xmlns="http://www.me.com">...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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
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...

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.