473,587 Members | 2,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlDocument.Sel ectNodes()

Hi
I'am using SelectNodes method to find if node followed by string exists, and
if so i going to select that node.

Create doc i such a way:
doc = new XmlDocument();

doc.AppendChild (doc.CreateXmlD eclaration("1.0 ", "UTF-8", null));

docHandle = doc.CreateEleme nt("Base");

doc.AppendChild (docHandle);

After that :

nodes = doc.SelectNodes (path);

IMy xmldocument represents directory structure, and before i add element i
check if each of directories ( dir1\dir2\...di rn ) exists.

Unfortunately 'nodes = doc.SelectNodes (path)' raises an exception 'Invalid
token in path'.

For any help - thanks


--

Pozdrawiam
Piotr Kolodziej
http://piotrkolodziej.waikru.info
Feb 19 '06 #1
16 19950
Hello PiotrKolodziej,

Does the Path query finds the node in your XML?
Can u test the query here http://www.activsoftware.com/xml/xpath/ first to
check it u are requesting the right nodes?

P> Hi
P> I'am using SelectNodes method to find if node followed by string
P> exists, and
P> if so i going to select that node.
P> Create doc i such a way:
P> doc = new XmlDocument();
P> doc.AppendChild (doc.CreateXmlD eclaration("1.0 ", "UTF-8", null));
P> docHandle = doc.CreateEleme nt("Base");
P> doc.AppendChild (docHandle);
P> After that :
P> nodes = doc.SelectNodes (path);
P> IMy xmldocument represents directory structure, and before i add
P> element i check if each of directories ( dir1\dir2\...di rn ) exists.
P>
P> Unfortunately 'nodes = doc.SelectNodes (path)' raises an exception
P> 'Invalid token in path'.

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Feb 19 '06 #2
> Does the Path query finds the node in your XML?
Can u test the query here http://www.activsoftware.com/xml/xpath/ first to
check it u are requesting the right nodes?


The node is not always present in XMLdoc. In fact i'am using it in such a
way:
IF the node exists, select the nodes.
Important is that i want to find the node starting from the parent node.
Feb 19 '06 #3
PiotrKolodziej <pi************ *@gmail.com> wrote:
I'am using SelectNodes method to find if node followed by string exists, and
if so i going to select that node.
<snip>
Unfortunately 'nodes = doc.SelectNodes (path)' raises an exception 'Invalid
token in path'.


Well, that sounds like it's a problem with the path you're using -
which unfortunately you didn't post.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 19 '06 #4
> Well, that sounds like it's a problem with the path you're using -
which unfortunately you didn't post.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.


Unfortunatly method is 1k lines and it's hard to get what is important.
Well. I also tought that path might me wrong. It's not.
I checked it for invalid characters and so on.
Now i'am beginning to think that maybe i shouln't use SelectNodes method to
select nodes that doesn't exists.
PK
Feb 19 '06 #5
Anyway here is first ver. of the method:

static private XmlNode checkEgsistance (ref ArrayList mList)

{

string path = null;

XmlNodeList nodes = null, temp = null;

foreach (object var in mList)

{

path += "/" ;

path += var.ToString();

nodes = doc.SelectNodes (path);

if (nodes.Count == 0)

{

toAdd = true;

if (temp != null)

{

return temp.Item(0).Pa rentNode;

}

else

{

return doc;

}

}

temp = nodes;

// Modify mList

mList.Remove(va r);

}

// Never returned

return doc;

}
Feb 19 '06 #6
PiotrKolodziej <pi************ *@gmail.com> wrote:
Well, that sounds like it's a problem with the path you're using -
which unfortunately you didn't post.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
Unfortunatly method is 1k lines and it's hard to get what is important.


I don't think so. Most of the method is unlikely to be relevant. The
sample program should probably:

1) Load a piece of XML from a string.
2) Select the nodes from it with a path which is also hard-coded.

I have to say, however, that any method which is 1000 lines long should
really, really be refactored. I don't like having *classes* that long
if I can avoid it...
Well. I also tought that path might me wrong. It's not.
I checked it for invalid characters and so on.
Well, there are plenty of ways in which a path can be invalid other
than invalid characters. It would really help to see it, given that the
exception sounds pretty definite in thinking it's bad.
Now i'am beginning to think that maybe i shouln't use SelectNodes method to
select nodes that doesn't exists.


No, that should be fine.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 19 '06 #7
PiotrKolodziej <pi************ *@gmail.com> wrote:
Anyway here is first ver. of the method:

static private XmlNode checkEgsistance (ref ArrayList mList)


<snip>

Out of interest, why is that a "ref" parameter? I can't see anything
which modifies the value of the variable (as opposed to the object it
refers to).

See http://www.pobox.com/~skeet/csharp/parameters.html for more
information.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 20 '06 #8

Out of interest, why is that a "ref" parameter? I can't see anything
which modifies the value of the variable (as opposed to the object it
refers to).


Because i cut from the method what is not important, when i post here.
Feb 20 '06 #9
Thanks everyone. I solved the problem.
The problem was that Xpath family is not accepting white characters: in my
case - spaces.

I was forced to replace spaces with '_'.


Feb 20 '06 #10

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

Similar topics

2
6199
by: Dave | last post by:
Hi, Is there an easier way to pull a subset of nodes from one XmlDocument to another? I have the code below but would like to know if there is a more streamlined method. Thanks, Dave XmlNodeList nodeList = doc1.SelectNodes("//row"); foreach (XmlNode nodeCode in nodeList) { sb.Append(nodeCode.OuterXml);
7
4887
by: SQLScott | last post by:
I have a Web Service in which I am trying to pass an XMLDocument as a parameter to one of the methods. I would like to use the XMLTextReader to read the XML but I am getting the following error: Value of type System.xml.xmldocument cannot be converted to System.IO.textreader. I would think this is possible to do. Code snippet is below:
8
6156
by: pete | last post by:
Hi there, Can someone explain to me why I can't bind to an XmlDocument but I can bind to an XmlNodeList. It's my understanding that they both implement the IEnumerable interface which is required for databinding. Am happy to work with the XmlNodeList but I can't shake the feeling I'm missing something <blush> Thanks, Pete
2
1756
by: Michael H | last post by:
Hello group, I have a some xml that looks like this below: <tuneRequests ct="3" xmlns:sql="urn:schemas-microsoft-com:xml-sql" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <tr xsi:type="trGenericType" number="2">
1
9645
by: Peter Nofelt | last post by:
Hey All, I'm running into this issue with parsing through an xml document by tag name. Below is an example xml document: File Name: things.xml <things> <people> <name>Peter</name>
4
1451
by: Roshawn Dawson | last post by:
Hi, I don't know why, but I can't seem to get this to work: Public Sub DoSomething() Dim sb as New StringBuilder() sb.Append("http://webservices.amazon.com/onca/xml?") sb.Append("Service=AWSECommerceService&SubscriptionId") sb.Append("=0525E2PQ81DD7ZTWTK82&Operation=ItemSearch") sb.Append("&SearchIndex=Books&Keywords=css")
3
3010
by: Stuart Shay | last post by:
Hello All In the following XML Below which is a XMLDocument in my application. I want to remove the <extensions></extensions> Node completely. What is the best way to do this, my files are not that large Thanks Stuart
0
2405
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: XmlDocument.SelectNodes call hangs EVERY TIME when selected nodes count is greater than 0. I have...
1
1698
by: =?Utf-8?B?RGF2aWRHQg==?= | last post by:
OK, so I've created and loaded an XMLDocument object. But how do I go about using it? Specifically, how do I: 1) move to the first node (I assume I start on it when I load the XML?) 2) move to the next node (.read?) 3) move back to a previous node? Is there a sample program somewhere to show this? (preferably VB.net) TIA David
0
7857
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8220
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
8352
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...
0
8222
tracyyun
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6632
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...
0
5396
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
3846
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2367
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
0
1194
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.