469,332 Members | 6,650 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,332 developers. It's quick & easy.

Bizzare Select single node problem

PT
Hi,
I've a simple XML tree that is essentially.

<?xml version="1.0"?>
<Project>
<Version Version="1.001" />
<Platform Name="Platform1"/>
<Platform Name="Platform2" />
</Project>

Now I have the following code.

XmlNode destinationProjectNode = doc1.SelectSingleNode("//Project");
string xPath = string.Format("{Platform}[@Name='Platform1']");
XmlNode destinationXmlNode = destinationProjectNode.SelectSingleNode(xPath);

This will retrieve the correct node as you'd expect, however in certain
cases and I can't find out why, is the node that is returned has null set
for it's parent, which means it can't be deleted because it thinks it's not
a child of any given node, I checked the body of Project and law and behold
it wasn't there, but, if it's it wasn't there, how did SelectSingleNode pick
it up ?? :/

Any pointers on this would be helpful.

Actually thinking about it, when you do a removechild node, is there
anything else you have to do to remove it from the xml ? as I know when you
bring one node in from a different xml you have to do an importnode and then
an appendchild, so I'm wondering if the node is still lingering around
somewhere but it's actually attached to anything, then again, you'd expect
selectsinglenode not to find it.. sorry, I'm just confused :)

Regards,

PT.

Dec 11 '06 #1
3 3451
PT wrote:
string xPath = string.Format("{Platform}[@Name='Platform1']");
What exactly is that line supposed to do? That does not look right.

If you think you have a problem with the parent node of some node then
consider posting a minimal but complete code sample that allows us to
reproduce the problem.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Dec 11 '06 #2
PT
Sorry about that, I took params off to give a clearer example but forgot to
take the braces off, so should have read.

string xPath = string.Format("Platform[@Name='Platform1']");

I'll try to get a simple sample that busts because it's part of a recursive
procedure, all I know via debugging is that selectsinglenode will return a
node who's parent element is null.
"Martin Honnen" <ma*******@yahoo.dewrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
PT wrote:
>string xPath = string.Format("{Platform}[@Name='Platform1']");

What exactly is that line supposed to do? That does not look right.

If you think you have a problem with the parent node of some node then
consider posting a minimal but complete code sample that allows us to
reproduce the problem.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Dec 11 '06 #3
PT
as usually the case, post on the forums, fix your own bug :) was a stupid
missing break; command in a loop that scanned attributes.. the shame.

Cheers,

PT

"Martin Honnen" <ma*******@yahoo.dewrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
PT wrote:
>string xPath = string.Format("{Platform}[@Name='Platform1']");

What exactly is that line supposed to do? That does not look right.

If you think you have a problem with the parent node of some node then
consider posting a minimal but complete code sample that allows us to
reproduce the problem.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Dec 12 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Colman | last post: by
1 post views Thread by Zri Man | last post: by
2 posts views Thread by naima.mans | last post: by
reply views Thread by Atos | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by haryvincent176 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.