473,802 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Selec tSingleNode("fi eld[@name='merchant _id']");

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

XmlNode dataNode = offerNode.Selec tSingleNode("fi eld[@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.Compi le(("field[@name='name']");
XPathNodeIterat or iter = navigator.Selec t(searchData);

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


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.Selec tSingleNode("fi eld[@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.Loa dXml(xmlSource) ;

XmlElement offerElement = xmlDocument.Doc umentElement;

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

Console.WriteLi ne("SelectSingl eNode result: {0}.", field);
}
}

I get the output

SelectSingleNod e result: System.Xml.XmlE lement.

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.Selec tSingleNode("fi eld[@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.Loa dXml(xmlSource) ;

XmlElement offerElement = xmlDocument.Doc umentElement;

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

Console.WriteLi ne("SelectSingl eNode result: {0}.", field);
}
}

I get the output

SelectSingleNod e result: System.Xml.XmlE lement.

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
8133
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? Thanks, JJ
3
8121
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 run the class it gives an error that "System.Xml.XmlNode.XmlNode() is inaccessible due to its protection level". This error comes because XmlNode has not any public constructor. I found XmlNode has two constructor but both are private or friend...
5
5101
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 xsi:type="a4:Customer+CustomerPayOptions" xmlns:a4="http://schemas.microsoft.com/clr/nsassem/OsfDomain.Resources.Stage/OsfDomain%2C%20Version%3D1.0.0.1%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">cash</PayPerference> I now want to add this XmlNode to a different...
5
2144
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 run the class it gives an error that "System.Xml.XmlNode.XmlNode() is inaccessible due to its protection level". This error comes because XmlNode has not any public constructor. I found XmlNode has two constructor but both are private or friend...
3
5060
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 datagrid, by extracting the <CustomerData></CustomerData> block from the xmlnode. Below is the sample of xmlnode return from webservices. <?xml version="1.0" encoding="utf-8"?>
7
1763
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 (ByVal Value As String)
1
313
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 with the way the .NET framework appears to handle the XmlNode, in particular the generation of the WSDL. The details follow: I define the code behind method as
4
4576
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>"; System.Xml.XmlDocument pdoc = new System.Xml.XmlDocument(); pdoc.LoadXml(sdoc); System.Xml.XmlNode pnode = pdoc.SelectSingleNode("//foo/bar/matches(.,'\\d')"); string foo = pnode.InnerText; int i23 = 23 + 23;
3
2884
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 "XMLNode does not exist in the current context.": XmlDocument XMLDoc = new XmlDocument(); XmlNode Node = XMLNode;
0
9699
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, 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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10538
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...
1
10285
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10063
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
9115
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
6838
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
5494
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
4270
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
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.