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

Read node text.

MA
Hi all!

I have a function that reads a nodes 'InnerText'. But when the node has
childs 'InnerText' includes that childs text to. Is there a way to select
the value from the node but not from the child?

my xml document structure looks like this:

<Root>
<Depth1>
<Depth2 with attributes>
<Depth3>
<Depth4></Depth4>
<Depth4></Depth4>
<Depth5></Depth5>
<Depth4></Depth4>
</Depth3>
<Depth3>
<Depth4></Depth4>
<Depth4></Depth4>
<Depth4>
<Depth5></Depth5>
</Depth4>
</Depth3>
</Depth2>
<Depth2 with attributes>
<Depth3>
<Depth4></Depth4>
<Depth4></Depth4>
<Depth5></Depth5>
<Depth4></Depth4>
</Depth3>
<Depth3>
<Depth4></Depth4>
<Depth4></Depth4>
<Depth5></Depth5>
<Depth4></Depth4>
</Depth3>
</Depth2>
<Depth1>
</Root>

For each "depth" I have to read its value/text and calculate those values.

Is the question to week, or doés anyone have any ideas?

/Marre
Nov 12 '05 #1
2 3202


MA wrote:

I have a function that reads a nodes 'InnerText'. But when the node has
childs 'InnerText' includes that childs text to. Is there a way to select
the value from the node but not from the child?


You can easily iterate over the ChildNodes and assemble the direct
content of child text nodes:

public static string GetChildText (XmlNode node) {
string text = "";
foreach (XmlNode child in node.ChildNodes) {
if (child.NodeType == XmlNodeType.Text) {
text += child.Value;
}
}
return text;
}

Then use it e.g.

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(@"test2004092801.xml");
XmlNodeList nodeList = xmlDocument.GetElementsByTagName("*");
foreach (XmlNode node in nodeList) {
Console.WriteLine("Text is:\r\n{0}\r\n------------\r\n",
GetChildText(node));
}

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
MA
> MA wrote:

I have a function that reads a nodes 'InnerText'. But when the node has
childs 'InnerText' includes that childs text to. Is there a way to select
the value from the node but not from the child?


You can easily iterate over the ChildNodes and assemble the direct content
of child text nodes:

public static string GetChildText (XmlNode node) {
string text = "";
foreach (XmlNode child in node.ChildNodes) {
if (child.NodeType == XmlNodeType.Text) {
text += child.Value;
}
}
return text;
}

Then use it e.g.

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(@"test2004092801.xml");
XmlNodeList nodeList = xmlDocument.GetElementsByTagName("*");
foreach (XmlNode node in nodeList) {
Console.WriteLine("Text is:\r\n{0}\r\n------------\r\n",
GetChildText(node));
}

Ok!
I´ll try that.

Thanks for youre answer!!

/Marre
Nov 12 '05 #3

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

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
2
by: Michael Winter | last post by:
Below is the IDL definition of the HTMLOptionElement. interface HTMLOptionElement : HTMLElement { readonly attribute HTMLFormElement form; attribute boolean defaultSelected;...
2
by: Raghu Gupta | last post by:
Hi, Actually i am facing some problem using quickbooks and presently i am not so expert in using it. I am using c# code to retrive the data from quickbooks. it doesn't matter which language we...
1
by: David | last post by:
All I am using the code below in order to read an XML file in the format: <root> <selection-attr attr="p70"> <value code="Mr">Mr</value> <value code="Mrs">Mrs</value> <value...
0
by: XML newbie: Urgent pls help! | last post by:
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it verifies the login information it should display the SessionID and enable some button . I appreciate your help and thanku...
3
by: Dan Aldean | last post by:
Hi, I create this XML document: <?xml version="1.0"?> <Bookstore> <Book Genre="Novel" Style="hardcover"> <author> <first-name>Margaret</first-name> <last-name>Atwood</last-name> </author>
9
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
2
by: Pugi! | last post by:
Using AJAX I want to send some information from the server (php-page) as XML to the client. The contents can be very divers so I have to use XML instead of text. On one occasion the contents is...
13
by: rohit | last post by:
Hi All, I am new to C language.I want to read integers from a text file and want to do some operation in the main program.To be more specific I need to multiply each of these integers with another...
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:
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
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,...
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.