473,796 Members | 2,607 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem reading the xmlelement value

I am trying to read all orders element, which have the attribute
Phase="Reorgani ze". 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='Reorgan ize']");
foreach (XmlElement Node in Nodes)
{
string S = Node.InnerText;
}
}

<?xml version="1.0" encoding="utf-8"?>
<OrderFile Version="1.0">
<Orders>
<Order Phase="Reorgani ze">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 3807
Michael Søndergaard wrote:
I am trying to read all orders element, which have the attribute
Phase="Reorgani ze". 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='Reorgan ize']");
foreach (XmlElement Node in Nodes)
{
string S = Node.InnerText;
}
}

<?xml version="1.0" encoding="utf-8"?>
<OrderFile Version="1.0">
<Orders>
<Order Phase="Reorgani ze">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='Reorgan ize']/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
6063
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 xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance">
1
2597
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 relations". The file has a number of parent nodes at the "<ShipmentHeader>" level, each of which have a number of child nodes. I will not know ahead of time which of these parent/child nodes will occur. I have also looked at the XmlTextReader, but it...
1
5810
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 Dim nodess As XmlNode nodess = myNode.SelectSingleNode("//Web") If nodess Is Nothing Then SQLrw.Delete()
2
7671
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 machine with Excel 2002 (version 10.0) installed - and the code works fine. I then test the code on a laptop running Excel 2000 (version 9.0) and it
13
2621
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 over my head - lol! The structure of the xml file I'm trying to append to is as follows: <?xml version="1.0" encoding="UTF-8"?> <!-- stuff -->
3
7968
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> <dir>MyDir2</dir> <file>
2
1467
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"?> <ISBNdb server_time="2005-02-25T23:03:41"> <BookList total_results="1" page_size="10" page_number="1" shown_results="1">
3
1667
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 format which I need to be able to add and remove records from. (I can not change this xml file format.) <country name="United Kingdom"> <city name="City1"> <street name="15 Street Address"> <details>
1
2298
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 then have my program access those values. I choose to store the information in an XML file based on a recommendation from a peer. I am also new to XML but my current file setup looks like this: <?xml version="1.0" encoding="utf-8" ?>...
0
9685
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
10237
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10187
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
9055
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...
1
7553
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6795
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
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
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
3735
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.