473,386 Members | 1,609 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.

Problem reading the xmlelement value

I am trying to read all orders element, which have the attribute
Phase="Reorganize". I am using the following code on the xml document.

private void LoadPhase (XmlDocument Doc, TreeNode Parent, Phase OrderPhase)
{
XmlNodeList Nodes =
Doc.SelectNodes("/OrderFile/Orders/Order[@Phase='Reorganize']");
foreach (XmlElement Node in Nodes)
{
string S = Node.InnerText;
}
}

<?xml version="1.0" encoding="utf-8"?>
<OrderFile Version="1.0">
<Orders>
<Order Phase="Reorganize">DA-(1)
<PhaseError>I dont want this text</PhaseError>
</Order>
<Order UniqueId="1" Phase="Politics">DPR-(2)</Order>
</Orders>
</OrderFile>

My problem is that the Node.InnerText gives me all the following test
"DA-(1)<PhaseError>I dont want this text</PhaseError>, What I need is the
"DA-(1)" part.

How do only read the current elements value and not all it childs nodes?

I checked all the properties of the Node using the debugger, but apparently
none of them contains only the element own value

Michael Søndergaard

Nov 12 '05 #1
1 3790
Michael Søndergaard wrote:
I am trying to read all orders element, which have the attribute
Phase="Reorganize". I am using the following code on the xml document.

private void LoadPhase (XmlDocument Doc, TreeNode Parent, Phase OrderPhase)
{
XmlNodeList Nodes =
Doc.SelectNodes("/OrderFile/Orders/Order[@Phase='Reorganize']");
foreach (XmlElement Node in Nodes)
{
string S = Node.InnerText;
}
}

<?xml version="1.0" encoding="utf-8"?>
<OrderFile Version="1.0">
<Orders>
<Order Phase="Reorganize">DA-(1)
<PhaseError>I dont want this text</PhaseError>
</Order>
<Order UniqueId="1" Phase="Politics">DPR-(2)</Order>
</Orders>
</OrderFile>

My problem is that the Node.InnerText gives me all the following test
"DA-(1)<PhaseError>I dont want this text</PhaseError>, What I need is the
"DA-(1)" part.

How do only read the current elements value and not all it childs nodes?


In XPath data model element's string value is concatenation of values of
descendant text nodes - exactly what you get. What you want is first
text node child of Order element -
/OrderFile/Orders/Order[@Phase='Reorganize']/text()[1]
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 12 '05 #2

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

Similar topics

3
by: John R. | last post by:
I have an application written in C# and i am using MS XML DOM! I have a document with the following structure (only the <DicEntry> - Elements are important): <NewDataSet...
1
by: davis | last post by:
Hello, I am working in .Net C# and have an xml file similar to the one below. I have tried using a DataSet but get the error "The same table (Gid) cannot be the child table in two nested...
1
by: Robert | last post by:
I am having a problem selecting nodes using the XMLnodelist Selectnodes using XPATH when I use XML SPY is successfully queries but when is use VB.net it comes up with nothing. Here is my code ...
2
by: Lenonardo | last post by:
Hi. I'm writing a VB.Net application to update multiple Excel Worksheets. I'm using late binding (i.e. all variables are objects + use createobject) I develop the application on an XP...
13
by: sherifffruitfly | last post by:
Hi all, I'm trying to distill all of the info from google searches into what I need, with partial success. In truth, the whole xmlNode, Document, Element, etc group of classes & methods is going...
3
by: Gina_Marano | last post by:
Hey All, There are many ways to skin a dog (I like cats so no cats) in .Net I have an XML string in the following format (without linefeeds): <remoteDir> <dir>MyDir</dir>...
2
by: jimmy | last post by:
Hi, I have an XML string that has been returned using a WebRequest object that i now need extract some data from. Some sample data is shown below. <?xml version="1.0" encoding="UTF-8"?>...
3
by: maw | last post by:
Hi, could somebody point me in the right direction for adding, removing and modifying nodes in an xml file programatically using vb.net (.net framework 2.0)? I have an xml file in the following...
1
by: nitusa | last post by:
Hi All, First time poster, and newbie C# programmer so be patient with my ignorance. :) For my current project I need to store some information (install dir., file names, passwords, ect.) and...
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
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: 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
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
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...
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
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...

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.