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

[Help]It returns 0 when using C# to process XML.

Here is the XML in a file:
<?xml version='1.0' encoding='utf-8' ?>
<bkxml version='1.0' xmlns='http://www.w3.org/2003/03/bkxml'>
<model>
<data name="angle" expr="100"></data>
<data name="sample" expr="200"></data>
</model>
</bkxml>
I use
XmlDocument.DocumentElement.SelectNode("/bkxml/model/data").Count,but
it returns 0. It will work once xmlns is omitted. However I have
defined Bkxml.xsd well, and validation is ok.

Who have experienced the same problem? Could you explain the reason?

Thank you!

Sand

Aug 29 '06 #1
2 1448
wi******@gmail.com wrote:
Here is the XML in a file:
<?xml version='1.0' encoding='utf-8' ?>
<bkxml version='1.0' xmlns='http://www.w3.org/2003/03/bkxml'>
<model>
<data name="angle" expr="100"></data>
<data name="sample" expr="200"></data>
</model>
</bkxml>
I use
XmlDocument.DocumentElement.SelectNode("/bkxml/model/data").Count,but
it returns 0. It will work once xmlns is omitted. However I have
defined Bkxml.xsd well, and validation is ok.

Who have experienced the same problem? Could you explain the reason?
Namespace issue. You select nodes from the null namespace. But the
elements in your XML are in the 'http://www.w3.org/2003/03/bkxml'
namespace. Read up about mapping prefixes to namespace URIs and then use
a prefix in the XPath.
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)
Aug 29 '06 #2
wi******@gmail.com wrote:
XmlDocument.DocumentElement.SelectNode("/bkxml/model/data").Count,but
it returns 0. It will work once xmlns is omitted.
XPaths are namespace-aware. You must use a prefix in your XPath and
provide the XPath evaluator with context information that binds that
prefix to the appropriate namespace, even if the default-namespace
syntax was used in the document. The only alternative is the ugly one of
writing XPaths with wildcards and then using predicates to test their
names -- which, among its other flaws, runs less efficiently in some
processors.
--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Aug 29 '06 #3

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

Similar topics

9
by: J. Campbell | last post by:
I'm comfortable with arrays from previous programming, and understand the advantages of c++ vectors...I just don't understand how to use them :~( Can you help me to use a vector<string> in the...
1
by: Alex | last post by:
I have a form that when the user click's the "What's This" question mark and the form's section, a pop-up help screen appears. I would like to automatically display this pop-up help context when...
0
by: Daniel | last post by:
hi, I want to find all the objects in my ascx embeded in another ascx of aspx. How can i use JavaScript loop through all the objects in order to find the name i want. For instance, using...
8
by: trialproduct2004 | last post by:
Hi all. I am having application in vb.net. I am having module and one form. From module i am opening form. On main itself i am checking whether another instance of application is running or...
2
by: shivaranjani.s.adimulam | last post by:
Hi, I have a .NET application where I want to restore the previos application if it is already running and in minimized state. The code I added is working fine in the case if the previous...
4
by: Charles | last post by:
I am doing a Digital signal processing project using VB.net and need advance maths function and also signal processing function such as fast fourier transform. Can anyone advice me on how do I get...
1
by: Bishman | last post by:
Hi, I have an odd problem that someone else may have come accross. VS2005 Pro. Fulll MSDN Installed. Search set up to only go local (Not online) On Friday I noticed that I was getting no...
0
by: Deven Oza | last post by:
please help me to solve the query. (Using Case statements) Write PL/SQL code such that: the user will input a letter (A, B, C); the letter will refer to a case statement that will ask for...
2
by: CharlesHawk | last post by:
HI i am working on a Project where i have to send a string using Sessions to the next page this is working gud for now But i can convert session to a string the .ToString(); and the...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...

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.