473,395 Members | 2,192 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.

Innertext and XPathNavigator.Value

I'm navigating through a XPathDocument consisting of mostly mixed complex
type elements (i.e. innertext plus more elements). When I use
XPathNavigator.Value to retrieve the text I get everything between <mytag>
and </mytag>, the text I'm looking for, but also all the text portion of
every sub tag (but not the tags themselves).

Is there a method in the MVP XML library or some other work around I can
user to get only the text of the parent tag?
Jan 21 '06 #1
4 7419


Jack Fox wrote:
I'm navigating through a XPathDocument consisting of mostly mixed complex
type elements (i.e. innertext plus more elements). When I use
XPathNavigator.Value to retrieve the text I get everything between <mytag>
and </mytag>, the text I'm looking for, but also all the text portion of
every sub tag (but not the tags themselves).

Is there a method in the MVP XML library or some other work around I can
user to get only the text of the parent tag?


I am not sure I understand what you want exactly (some XML sample would
have helped) but if you want the text of child text nodes then you could
select those e.g. if the navigator is positioned on your mytag element
XPathNodeIterator iterator = navigator.SelectChildren(XPathNodeType.Text);
and use the iterator to get those text node values and concatenate them
(using string concatenation or a StringBuilder if needed) e.g.
string childText = "";
while (iterator.MoveNext()) {
childText += iterator.Current.Value;
}
// now use childText here

The element itself has no text, anything in there is a child node.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jan 21 '06 #2
<parent>parent text
<child>child text</child>
</parent>

When XPathNavigator is positioned on parent and I look at the Value
property, what I get is "parent textchild text". I want only "parent text".

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:uY**************@TK2MSFTNGP10.phx.gbl...


Jack Fox wrote:
I'm navigating through a XPathDocument consisting of mostly mixed complex
type elements (i.e. innertext plus more elements). When I use
XPathNavigator.Value to retrieve the text I get everything between
<mytag> and </mytag>, the text I'm looking for, but also all the text
portion of every sub tag (but not the tags themselves).

Is there a method in the MVP XML library or some other work around I can
user to get only the text of the parent tag?


I am not sure I understand what you want exactly (some XML sample would
have helped) but if you want the text of child text nodes then you could
select those e.g. if the navigator is positioned on your mytag element
XPathNodeIterator iterator =
navigator.SelectChildren(XPathNodeType.Text);
and use the iterator to get those text node values and concatenate them
(using string concatenation or a StringBuilder if needed) e.g.
string childText = "";
while (iterator.MoveNext()) {
childText += iterator.Current.Value;
}
// now use childText here

The element itself has no text, anything in there is a child node.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Jan 21 '06 #3
OK, I figured out how to do this, it requires further XPath selection

XPathNodeIterator s = navCurHeading.Select("text()[1]");

s.MoveNext();

string ss = s.Current.Value;

"navCurHeading is the navigator positioned on your complex node (it has its
own text as well as children nodes with text. The XPath selection selects
the first text node into an iterator. Not quite as simple as I would have
expected, but it works.

"Jack Fox" <ja*****@ix.netcom.com> wrote in message
news:k1*****************@newsread1.news.pas.earthl ink.net...
I'm navigating through a XPathDocument consisting of mostly mixed complex
type elements (i.e. innertext plus more elements). When I use
XPathNavigator.Value to retrieve the text I get everything between <mytag>
and </mytag>, the text I'm looking for, but also all the text portion of
every sub tag (but not the tags themselves).

Is there a method in the MVP XML library or some other work around I can
user to get only the text of the parent tag?

Jan 21 '06 #4


Jack Fox wrote:
OK, I figured out how to do this, it requires further XPath selection

XPathNodeIterator s = navCurHeading.Select("text()[1]");

s.MoveNext();

string ss = s.Current.Value;

"navCurHeading is the navigator positioned on your complex node (it has its
own text as well as children nodes with text. The XPath selection selects
the first text node into an iterator. Not quite as simple as I would have
expected, but it works.


Well my suggestion was to select all child text nodes and then
concatenate while iterating. That seems more general. But if you want
only the text of the first child text node then use the above.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jan 22 '06 #5

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

Similar topics

1
by: Obe | last post by:
PLEASE HELP! I'm writing a function to populate DropDownLists from and xml file. I am having a problem getting my XPathNavigator to select any nodes when I attach a schema to my xml document. ...
1
by: chris yoker via DotNetMonster.com | last post by:
hiya, I add new nodes to an xmlDoc. I want to add "innerText" to every newly-created node. current XML file <code> <rows> <row> <PRODUCT-TYPE>bike</PRODUCT-TYPE>...
1
by: Phil | last post by:
Is there an easy way to get the schema's data type for a XPathNavigator value? I need to be able to determine the data type for the xml value based off of an unknown schema and unknown xml file...
6
by: David Thielen | last post by:
Hi; How can I tell if I can call XPathNavigator.ValueAsBoolean safely - without throwing an exception. I want to take one course of action if the value can be interpreted as a boolean. But I...
12
by: David Thielen | last post by:
Hi; I have an element: <space> </space> When I call SelectSingleNode() on it, the InnerXml is a 0 length String, not a String containing 1 space. Any ideas?
6
by: C# newbie | last post by:
Hello group, When I run an XPATH query first as: //*[contains(translate(.,\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\", \"abcdefghijklmnopqrstuvwxyz\")
13
by: Lyners | last post by:
I have a web page writen in ASP.NET that contains some javascript so that when a user presses a button, or edits a certain field in a datagrid, another cell in the datagrid is filled with a value....
1
by: SteZgr | last post by:
I have implemented in .NET 2.0 a custom XPathNavigator for Xpath filtering on an object tree. So far it works. While analyzing the performance, I have noticed a lot of MoveToNextAttribute calls. ...
0
by: kelvin273 | last post by:
Hi all, i'm new in this community (and in .NET programming) and i've a problem with xpathnavigator. The idea is to have an xml document with attribute editable by windows form. I write this...
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:
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: 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?
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
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...
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...

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.