473,385 Members | 2,044 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,385 software developers and data experts.

Retrieving JUST text from a node with child nodes

Hi all,

Can't seem to figure out how to retrieve the text of a node with multiple
child nodes (and I just want the text of the parent, not the InnerText or
InnerXML that comes with it).

My doc looks something like this:

<parent attrib1 attrib2 attrib3>
Extractable string
<child>
some more text
</child>
<child>
yet more text
</child>
</parent>

What's the best way to return "Extractable string"?
Nov 12 '05 #1
2 1466
You can either just select the text via an XPath expression like this:
/parent/text()

or, if your XmlDocument is not too complex, you can position an XmlReader at
the text node and read it like this

<outlookCode>
string GetText( XmlReader reader )
{
string text = null;
while( reader.Read() )
{
if( "parent" == reader.LocalName )
{
reader.MoveToContent(); // this will move to the first text or
element node.
if( NodeType.Text == reader.NodeType )
{
text = reader.Value();
}
break;
}
}
}
</outlookCode>
--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor
"Bjorn" <ba*******@tuvox.com> wrote in message
news:#0**************@TK2MSFTNGP10.phx.gbl...
Hi all,

Can't seem to figure out how to retrieve the text of a node with multiple
child nodes (and I just want the text of the parent, not the InnerText or
InnerXML that comes with it).

My doc looks something like this:

<parent attrib1 attrib2 attrib3>
Extractable string
<child>
some more text
</child>
<child>
yet more text
</child>
</parent>

What's the best way to return "Extractable string"?

Nov 12 '05 #2

"Bjorn" <ba*******@tuvox.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi all,

Can't seem to figure out how to retrieve the text of a node with multiple
child nodes (and I just want the text of the parent, not the InnerText or
InnerXML that comes with it).

My doc looks something like this:

<parent attrib1 attrib2 attrib3>
Extractable string
<child>
some more text
</child>
<child>
yet more text
</child>
</parent>

What's the best way to return "Extractable string"?

/*/text()[1]
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
Nov 12 '05 #3

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

Similar topics

2
by: MA | last post by:
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...
2
by: Urs Vogel | last post by:
Hi When using XmlDocument, I can create nodes and attributes as I like. What I didn't achieve is changing the Value of a node (created with createElement), it claims that it's the wrong node...
5
by: Jeroen Ceuppens | last post by:
I need to put a new node at the end of the tree, that end is not te lowest in de list but the deepest (the one with the most + before it) Node A Node 1 Node 2 Node 3 Node 4: Deepest Node B:...
3
by: Brian Henry | last post by:
If i already have a tree view created, and want to add another new node to it, how would i do so? Is there a way to throught tags or anything? like i have this RootNode | +-- Child 1 +--...
2
by: Debbie | last post by:
Is there a standard way to extract text from a web page, without using innertext/innerhtml? It's an academic exercise, and we've been advised that we can't use Internet Explorer DOM extensions...
3
by: Irocivan | last post by:
Hello, I download a nice collapse menu for free distribution from the internet. It works very well except that none of the parents nodes are clickable (i.e. when clicking on the parent node, the...
2
by: Maddy | last post by:
I need to populate a treeview from a text file. The data in it is in the following form 1. (Parent Node) (a) (Child Node) (b) (Child Node) .. .. .. (k) (Child Node)
5
by: SkipSailors | last post by:
I have some XML that I want to transform to some XML: <element> <child> <grandchild> otherWord </grandchild> <grandchild> triggerExclusion...
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:
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
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?
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
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.