473,386 Members | 1,630 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,386 software developers and data experts.

Possible bug in XmlNode

I have a XML document with elements like
<offer>
<field name="name"><![CDATA[DS SIL CON]]></field>
<field name="merchant_id"><![CDATA[3001]]></field>
.....
</offer>

I know not the best XML! Now I am selecting different values by XPath
having an XmlNode representing the <offer> element. Now when I try something
like this

XmlNode dataNode = offerNode.SelectSingleNode("field[@name='merchant_id']");

this works fine and returns a result. However the following query runs but
returns nothing:

XmlNode dataNode = offerNode.SelectSingleNode("field[@name='name']");

Now the only thing I can think of is that the attribute and text have the
same value. I tried the same query as an XPathExpression:

XPathExpression searchData = navigator.Compile(("field[@name='name']");
XPathNodeIterator iter = navigator.Select(searchData);

and surprise surprise it works.
So is this a bug in using the SelectNodes() or SelectSingleNode methods on
an XmlNode?
Nov 12 '05 #1
2 1470


J Mon wrote:
I have a XML document with elements like
<offer>
<field name="name"><![CDATA[DS SIL CON]]></field>
<field name="merchant_id"><![CDATA[3001]]></field>
....
</offer> However the following query runs but
returns nothing:

XmlNode dataNode = offerNode.SelectSingleNode("field[@name='name']");


This is a complete test case using your example XML and your example
XPath expression:

using System;
using System.Xml;

public class Test2005091901 {
public static void Main (string[] args) {
string xmlSource = @"<offer>
<field name=""name""><![CDATA[DS SIL CON]]></field>
<field name=""merchant_id""><![CDATA[3001]]></field>
</offer>";

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xmlSource);

XmlElement offerElement = xmlDocument.DocumentElement;

XmlNode field = offerElement.SelectSingleNode("field[@name='name']");

Console.WriteLine("SelectSingleNode result: {0}.", field);
}
}

I get the output

SelectSingleNode result: System.Xml.XmlElement.

with .NET 1.1 which seems fine to me, an element node is found.

Does that test case give a different result for you?

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
I stand corrected. Must be something deeper nested in the code that is
causing the XmlNode to be empty.

"Martin Honnen" wrote:


J Mon wrote:
I have a XML document with elements like
<offer>
<field name="name"><![CDATA[DS SIL CON]]></field>
<field name="merchant_id"><![CDATA[3001]]></field>
....
</offer>

However the following query runs but
returns nothing:

XmlNode dataNode = offerNode.SelectSingleNode("field[@name='name']");


This is a complete test case using your example XML and your example
XPath expression:

using System;
using System.Xml;

public class Test2005091901 {
public static void Main (string[] args) {
string xmlSource = @"<offer>
<field name=""name""><![CDATA[DS SIL CON]]></field>
<field name=""merchant_id""><![CDATA[3001]]></field>
</offer>";

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xmlSource);

XmlElement offerElement = xmlDocument.DocumentElement;

XmlNode field = offerElement.SelectSingleNode("field[@name='name']");

Console.WriteLine("SelectSingleNode result: {0}.", field);
}
}

I get the output

SelectSingleNode result: System.Xml.XmlElement.

with .NET 1.1 which seems fine to me, an element node is found.

Does that test case give a different result for you?

--

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

Nov 12 '05 #3

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

Similar topics

9
by: JJ | last post by:
Hi All, I noticed that XmlNode and XpathNavigator are quite similiar. XmlNode seems to navigate over an XML Doc and so does XPathNav so when do I use XPathNavigator instead of XmlNode? ...
3
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
5
by: Paul | last post by:
Here I have the definition of an XmlNode which is a property (PayPreference) on my Customer class containing an enum describing how the customer will pay. <PayPerference...
5
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
3
by: Mae | last post by:
Dear All, I have a problem here, I'm using C# Webform calling a webservices. The webservices return me a XMLnode, using this XMLnode I want to convert it to dataset so I can bind to the...
7
by: Buddy Ackerman | last post by:
I created this class Public Class HTMLFileInput : Inherits System.Web.UI.HtmlControls.HtmlInputFile Public Property Data As String Get Return ViewState("HTMLFileInput.Data") End Get Set...
1
by: PaulF | last post by:
I am writing a web service that accepts and returns an XML message - I know the issues behind this but want to be able to process the messages generically using XSD / XSLT. My problem occurs...
4
by: Daniel | last post by:
Is it possible to use regular expressions inside of an xpath statement executed by System.Xml.XmlDocument.SelectSingleNode() ? string sdoc = "<foo><bar a='1'/><bar a='2'/></foo>";...
3
by: Earl | last post by:
In VB.Net, the following declaration builds and executes with no exceptions: Dim XMLDoc As New XmlDocument Dim Node As XmlNode But in C#, the following (equivalent?!) returns the build error...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.