473,387 Members | 1,465 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,387 software developers and data experts.

XPathNavigator ignoring embedded tags

I'm using an XPathNodeIterator to select an element in an XML document that
contains text I am going to put in a label on an aspx page.

I want to be able to include HTML tags in the text read from the XML
document, but the XPathNodeIterator.Current.Value property seems to ignore
any tags. The text inside the tags is included, but the tags themselves are
not. Is this possible or
is there something else I need to do?

<root>
<home_page_quote>
This is a <b>test</b> for <i>fomatting</i>.
</home_page_quote>
</root>

XPathDocument xmlDoc = new XPathDocument(Server.MapPath("") + "\\Pages.xml");
XPathNavigator xmlNav = xmlDoc.CreateNavigator();
XPathNodeIterator xmlIt = xmlNav.Select("/root/home_page_quote");
xmlIt.MoveNext();
Label1.Text = xmlIt.Current.Value(); // Does not have the <b> or <i> tags
included.

Nov 12 '05 #1
4 2022


David wrote:

<root>
<home_page_quote>
This is a <b>test</b> for <i>fomatting</i>.
</home_page_quote>
</root>

XPathDocument xmlDoc = new XPathDocument(Server.MapPath("") + "\\Pages.xml");
XPathNavigator xmlNav = xmlDoc.CreateNavigator();
XPathNodeIterator xmlIt = xmlNav.Select("/root/home_page_quote");
xmlIt.MoveNext();
Label1.Text = xmlIt.Current.Value(); // Does not have the <b> or <i> tags
included.


The string value of an element node is the concatenation of the text
content of all child nodes.
Getting the markup is not supported directly in .NET 1.0 and 1.1, in 2.0
you can use
xmlIt.Current.InnerXml
If you want to use InnerXml in .NET 1.0 and 1.1 then you could switch
from XPathDocument to XmlDocument e.g. use code alike
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath(@"/Pages.xml"));
XmlElement element =
xmlDocument.SelectSingleNode("/root/home_page_quote") as XmlElement;
if (element != null) {
Label1.Text = element.InnerXml;
}

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
Thank you so much. I was wondering why there was no InnerXml property on
XPathNodeIterator.Current. You're solution works great!

"Martin Honnen" wrote:
The string value of an element node is the concatenation of the text
content of all child nodes.
Getting the markup is not supported directly in .NET 1.0 and 1.1, in 2.0
you can use
xmlIt.Current.InnerXml
If you want to use InnerXml in .NET 1.0 and 1.1 then you could switch
from XPathDocument to XmlDocument e.g. use code alike
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath(@"/Pages.xml"));
XmlElement element =
xmlDocument.SelectSingleNode("/root/home_page_quote") as XmlElement;
if (element != null) {
Label1.Text = element.InnerXml;
}

--

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

Nov 12 '05 #3
Hello!
I'm using an XPathNodeIterator to select an element in an XML document that
contains text I am going to put in a label on an aspx page.

I want to be able to include HTML tags in the text read from the XML
document, but the XPathNodeIterator.Current.Value property seems to ignore
any tags. The text inside the tags is included, but the tags themselves are
not. Is this possible or
is there something else I need to do?

<root>
<home_page_quote>
This is a <b>test</b> for <i>fomatting</i>.
</home_page_quote>
</root>


Another solution is to put your HTML into a CDATA-Section (if you just
want to copy the data into a template, this should be enough):

<root>
<home_page_quote><![CDATA[
This is a <b>test</b> for <i>formatting</i>.
]]></home_page_quote>
</root>
--
Pascal Schmitt
Nov 12 '05 #4
This will perform better if you can do it since it doesn't have to parse the
contents of the CDATA as a bunch of text and XML elements, then copy all
that out with InnerXml.

"Pascal Schmitt" <ne*******@cebra.nu> wrote in message
news:O9**************@TK2MSFTNGP14.phx.gbl...
Hello!
I'm using an XPathNodeIterator to select an element in an XML document
that contains text I am going to put in a label on an aspx page. I want
to be able to include HTML tags in the text read from the XML document,
but the XPathNodeIterator.Current.Value property seems to ignore any
tags. The text inside the tags is included, but the tags themselves are
not. Is this possible or is there something else I need to do?

<root>
<home_page_quote>
This is a <b>test</b> for <i>fomatting</i>.
</home_page_quote>
</root>


Another solution is to put your HTML into a CDATA-Section (if you just
want to copy the data into a template, this should be enough):

<root>
<home_page_quote><![CDATA[
This is a <b>test</b> for <i>formatting</i>.
]]></home_page_quote>
</root>
--
Pascal Schmitt

Nov 12 '05 #5

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

Similar topics

2
by: Aquarius2431 | last post by:
Hi!, I don't think I have posted to this group before. Have been using PHP on my webserver for a few months now and finding that I like it quite a bit. Here is a question that just occurred...
4
by: Luke Dalessandro | last post by:
I have some XML data that has mixed content XML tags that embed XHTML tags, for instance: <note>Somebody wrote this note in XHTML and wanto to <a href="link.html" target="_new">link</a> to a...
7
by: David Thielen | last post by:
Hi; Is there a way from an XPathNavigator object to get an xpath string that will, when used in a Select(xpath) on the underlying base/root XPathNavigator return the same XPathNavigator? In...
4
by: Jack Fox | last post by:
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...
2
by: MR | last post by:
I would like to create an htm file (using Word) that will have some free form text. However, in the free form text I would like to be able to embed some fields like Name, Address, etc. I have tried...
11
by: ericms | last post by:
Can anybody show me how to insert a CDATA section using XPathNavigator ? I have tried the follwing with no luck: XmlDocument docNav = new XmlDocument(); docNav.LoadXml(xmlString);...
4
by: dennis.mcknight | last post by:
new to php -- please help. it seems like php is treating any '>' character as the end of my code segment, even when it's embedded in a string, as shown <? $s="THIS IS MY TEST STRING"; ?> ...
8
by: Philip Ronan | last post by:
Hi, I recently discovered that Google's mobile search robot doesn't understand the "robots" Meta tag. Here's an example: ...
1
by: WestyCHC | last post by:
Morning all from a newbie. I have recently written an automation program (my first ever program) for testing and now I am trying to read XML data and assign the values to variables (rather than...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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
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
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,...

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.