I am having an issue trying to use the SelectNodes method in C# when
using an Xpath Query. I realize lots of people have posted on this
subject, but I have a little bit of a different variation.
Let's take the document
<MyNodes>
<MyNode Attrib1="Cat"/>
<MyNode Attrib1="Dog"/>
<MyNode OtherAttrib="Ho use"/>
<MyNodes/>
I want to be able to select from that document and get a list of
MyNode that has the Attrib1 attribute, but not those with OtherAttrib.
My Xpath query works fine if I do an absolute path, such as
/MyNodes/MyNode[@Attrib1]
However, if I try to use the relative version, such as
MyNodes/MyNode[@Attrib1]
then, the results are empty.
From reading in the groups, it seems that you need to provide a
NameSpace for the Xpath query to be valid.
My problem is I am using a XML document that is provided by another
party. They do not have a schema at all within the document.
What options do I have for getting a list of the nodes like I
identified above? Contacting the party about changing their XML
format isn't an options.
Thanks for any help
Endymion Keats 4 5310
I'm not sure that your problem has anything to do with namespaces or
schemas. The problem is most likely due to the fact that you are performing
a relative query on the wrong node.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Ender" <en*********@ho tmail.com> wrote in message
news:47******** *************** **@posting.goog le.com... I am having an issue trying to use the SelectNodes method in C# when using an Xpath Query. I realize lots of people have posted on this subject, but I have a little bit of a different variation.
Let's take the document
<MyNodes> <MyNode Attrib1="Cat"/> <MyNode Attrib1="Dog"/> <MyNode OtherAttrib="Ho use"/> <MyNodes/>
I want to be able to select from that document and get a list of MyNode that has the Attrib1 attribute, but not those with OtherAttrib.
My Xpath query works fine if I do an absolute path, such as
/MyNodes/MyNode[@Attrib1]
However, if I try to use the relative version, such as MyNodes/MyNode[@Attrib1] then, the results are empty.
From reading in the groups, it seems that you need to provide a NameSpace for the Xpath query to be valid.
My problem is I am using a XML document that is provided by another party. They do not have a schema at all within the document.
What options do I have for getting a list of the nodes like I identified above? Contacting the party about changing their XML format isn't an options.
Thanks for any help
Endymion Keats
My code looks like the following
--------
strXpathQuery = "MyNode[@Attrib1]";
// Get xml into Dom object
xmlDom= oCanvasNode.Xml ;
oQueryNodeList = xmlDom.Document Element.SelectN odes(strXpathQu ery );
if (oQueryNodeList .Count >0)
{
// Do something
}
--
As I understand it, if I don't use an absolute search, it should find
all nodes that meet the criteria, from the current node.
In this case all the MyNode nodes within the document.
If this is not the case, is there a way I can retrieve all nodes in a
document, independent of the node
they are on.
What I am trying to do is, at a high level, dynamically replace a set
of nodes with a value, where that value
is determined at run time. The nodes can be anywhere in the document.
XSLT is not an option.
Thanks
Endymion
Ender wrote: As I understand it, if I don't use an absolute search, it should find all nodes that meet the criteria, from the current node. In this case all the MyNode nodes within the document.
Nope, "MyNode[@Attrib1]" expression is shorthand for
"child::MyN ode[attribute::Attr ib1]" what in plain English is "MyNode
element, child of current node, which bears Attrib1 attribute".
If this is not the case, is there a way I can retrieve all nodes in a document, independent of the node they are on.
It's //MyNode[@Attrib1]
or better but longer
/descendant::MyN ode[@Attrib1]
Or as you call SelectNodes on DocumentElement , you can use
..//MyNode[@Attrib1]
or
descendant::MyN ode[@Attrib1]
Latter means "all MyNode elemens, descendants of current node, bearing
Attrib1 attribute".
--
Oleg Tkachenko
XML Insider http://www.tkachenko.com/blog
Thanks!
That worked, I appreciate the help.
Endymion Keats This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: suresh |
last post by:
Hi,
I have the following xml file.
<Navigator xmlns="urn:uuid:721DCCFA-8250-4820-8C7D-
7AF0E52305FD">
<SMDataSet RegionName="NA" CustomerName="ATT"
MarketName="New Jersey" DataSetName="SMDS1"
Technology="CDMA" StartDateAndTime="2003-06-
01T00:00:00.0000000-04:00" EndDate="2003-06-
|
by: Alexander Gnauck |
last post by:
Hello,
i have problems with the Namespaces and the .Net XML Parser
My XML looks like this:
<query xmlns="jabber:iq:roster">
<item jid="srlee@localhost" name="srlee"
subscription="both"><group>contacts</group></item>
<item jid="tlee@localhost" name="Troy"
subscription="both"><group>contacts</group></item>
|
by: MacDk |
last post by:
Hi,
Given this:
http://rss.asdf.dk/theothermusic.rss
how do you use selectnodes/Xpath to return all title-items (//title is
not working). I think it a problem with namespace but i can't solve
the problem.
|
by: Riko Eksteen |
last post by:
Hi
I am writing an application that listens to the NodeInserted event, and if
the event is fired it does a selectnodes xpath query on the XmlDocument.
Only problem is, when I call SelectNodes(string, XmlNameSpaceManager) the
NodeInserted event gets fired as well, without me doing any modifucation of
the document. This results in an...
|
by: Adrian Parker |
last post by:
I have the following xml doc...
<?xml version="1.0"?>
<GovTalkMessage xmlns="http://www.govtalk.gov.uk/CM/envelope">
<Body>
<StatusReport>
<StatusRecord>
<CorrelationID>E1308AB43036D8B8FCD2CBB1EE7FFA6B</CorrelationID>
</StatusRecord>
<StatusRecord>
| |
by: pneumoconi |
last post by:
I've read a lot of posts on this subject each with a slightly different
issue and from what I gather my code is fine. But its not. I'm trying
to pull out the SQL query from a SQL report document which looks
something like this:
<?xml version="1.0" encoding="utf-8"?>
<Report...
|
by: Linda Boumarafi |
last post by:
Hi,
This is a newbie question to XMLNS. I just finished the article on "XML
Namespaces and How They Affect XPath and XSLT" by Dare Obasanjo and I'm
pretty sure I understand the problem. I just don't know how to achieve the
desired XPath result. I'm dealing with an XML document that has two XMLNS' in
the root node (Report) and I'm ending up...
|
by: Jeppe BS |
last post by:
I got this simple XML file which im using the SelectNodes funktion on
and it works well.
Then i got this other XML file with the same structure as the first one
but every sub node contains a lot more elements and a lot of namespace
declarations. I m using allmost the same code for each XML file but the
last one wont work.
Been trying to...
|
by: Woon Kiat |
last post by:
I have this Xml file, bookstore.xml
<Bookstore xmlns="http://www.book.com">
<Shelve index="1">
<Book name="Da Vinci Code" />
</Shelve>
<Shelve index="2">
<Book name="The Holy Grail" />
</Shelve>
<Shelve index="3">
|
by: Karel Kral |
last post by:
Hello,
I have created simple COM service in .NET. COM is accessed from another
not NET application by late binding call.
And the problem:
If I call NetComClass.Hello from another .NET code, all works fine. But
when calling from COM, the program hangs at line nodeList =
root.SelectNodes("/bookstore/book"). CPU is utilized 100%. Briefly:...
|
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...
| |
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...
|
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. ...
|
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...
|
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...
|
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...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |