473,802 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XPathNavigator. SelectSingleNod e(xpath) on space returns 0 length s

Hi;

I have an element:
<space> </space>

When I call SelectSingleNod e() on it, the InnerXml is a 0 length String, not
a String containing 1 space.

Any ideas?

--
thanks - dave
Nov 12 '05 #1
12 3965
Hi dave,

You can set PreserveWhitesp ace to true, so that the space will be preserved.

XmlDocument doc = new XmlDocument();
doc.PreserveWhi tespace = true;
doc.LoadXml("<s pace> </space>");
XmlNode n = doc.SelectSingl eNode("space");
MessageBox.Show (n.InnerXml.Len gth.ToString()) ;

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #2
Hi;

Sorry - I forgot to mention - the API I give people is to pass in a
XPathNavigator. So it may not be an XmlDocument. And even if it is, I have no
way of accessing that object.

How do I do this for an XPathNavigator?

--
thanks - dave
"Kevin Yu [MSFT]" wrote:
Hi dave,

You can set PreserveWhitesp ace to true, so that the space will be preserved.

XmlDocument doc = new XmlDocument();
doc.PreserveWhi tespace = true;
doc.LoadXml("<s pace> </space>");
XmlNode n = doc.SelectSingl eNode("space");
MessageBox.Show (n.InnerXml.Len gth.ToString()) ;

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #3
Hi dave,

There is no way to preserve whitespace in the code directly with
XPathNavigator. You can try to do the following:

1. Add whiteSpace="pre serve" in the tag. <space whiteSpace="pre serve">
</space>
2. If the node is a whitespace, check the XPathNavigator. NodeType property,
it has to be XPathNodeType.S ignificantWhite space or
XPathNodeType.W hitespace.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #4
Hi;

It's not my xml. I have a library that other people call and pass me their
xml. I wrote all of my code using XPathDocument & XPathNavigator because it
is the "suggested" approach.

But I need to have whitespace preserved. There must be a way as Microsoft
suggests using this approach and not using XmlDocument at all. Could you
please ask the .net team? I find it hard to believe they would not have made
it possible to do this.

--
thanks - dave
"Kevin Yu [MSFT]" wrote:
Hi dave,

There is no way to preserve whitespace in the code directly with
XPathNavigator. You can try to do the following:

1. Add whiteSpace="pre serve" in the tag. <space whiteSpace="pre serve">
</space>
2. If the node is a whitespace, check the XPathNavigator. NodeType property,
it has to be XPathNodeType.S ignificantWhite space or
XPathNodeType.W hitespace.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #5
I'm on the .net xml team and I know for sure that once you've loaded an
XmlDocument without preserveWhitesp ace, you have lost all insignificant
whitespace information and there is no way for the XPathNavigator to
"reinvent" it on the fly. Therefore you'll have to tell folks who are
calling you not to do that. Or you chould change your component design so
that they call you to load the XML that way you can be in control of how the
whitespace processing happens.

"David Thielen" <th*****@nospam .nospam> wrote in message
news:71******** *************** ***********@mic rosoft.com...
Hi;

It's not my xml. I have a library that other people call and pass me their
xml. I wrote all of my code using XPathDocument & XPathNavigator because
it
is the "suggested" approach.

But I need to have whitespace preserved. There must be a way as Microsoft
suggests using this approach and not using XmlDocument at all. Could you
please ask the .net team? I find it hard to believe they would not have
made
it possible to do this.

--
thanks - dave
"Kevin Yu [MSFT]" wrote:
Hi dave,

There is no way to preserve whitespace in the code directly with
XPathNavigator. You can try to do the following:

1. Add whiteSpace="pre serve" in the tag. <space whiteSpace="pre serve">
</space>
2. If the node is a whitespace, check the XPathNavigator. NodeType
property,
it has to be XPathNodeType.S ignificantWhite space or
XPathNodeType.W hitespace.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #6
Hello;

First off, thank you for answering. Getting a definite no helps as then I
know that I'm not missing something.

Most cases I am passed a Stream so I can call new XmlDocument(Str eam)
instead of new XPathDocument(S tream). But all of the documentation I have
read says that XPathDocument is a lot faster for heavy xpath use - so do I
then lose that efficiency?

And out of curiosity, why does XPathDocument eat all of the whitespace?
Because xml schemes like Excel's SpreadsheetML need it.

--
thanks - dave
"Chris Lovett" wrote:
I'm on the .net xml team and I know for sure that once you've loaded an
XmlDocument without preserveWhitesp ace, you have lost all insignificant
whitespace information and there is no way for the XPathNavigator to
"reinvent" it on the fly. Therefore you'll have to tell folks who are
calling you not to do that. Or you chould change your component design so
that they call you to load the XML that way you can be in control of how the
whitespace processing happens.

"David Thielen" <th*****@nospam .nospam> wrote in message
news:71******** *************** ***********@mic rosoft.com...
Hi;

It's not my xml. I have a library that other people call and pass me their
xml. I wrote all of my code using XPathDocument & XPathNavigator because
it
is the "suggested" approach.

But I need to have whitespace preserved. There must be a way as Microsoft
suggests using this approach and not using XmlDocument at all. Could you
please ask the .net team? I find it hard to believe they would not have
made
it possible to do this.

--
thanks - dave
"Kevin Yu [MSFT]" wrote:
Hi dave,

There is no way to preserve whitespace in the code directly with
XPathNavigator. You can try to do the following:

1. Add whiteSpace="pre serve" in the tag. <space whiteSpace="pre serve">
</space>
2. If the node is a whitespace, check the XPathNavigator. NodeType
property,
it has to be XPathNodeType.S ignificantWhite space or
XPathNodeType.W hitespace.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."


Nov 12 '05 #7
XPathDocument (and XmlDocument) default to preserveWhitesp ace=false for
backward compatibility reasons.

But you can tell both of these to preservice whitespace as follows:

new XPathDocument(@ "..\\..\\xmlfil e1.xml", XmlSpace.Preser ve);

and
XmlDocument xdoc = new XmlDocument();
xdoc.PreserveWh itespace = true;
"David Thielen" <th*****@nospam .nospam> wrote in message
news:8F******** *************** ***********@mic rosoft.com...
Hello;

First off, thank you for answering. Getting a definite no helps as then I
know that I'm not missing something.

Most cases I am passed a Stream so I can call new XmlDocument(Str eam)
instead of new XPathDocument(S tream). But all of the documentation I have
read says that XPathDocument is a lot faster for heavy xpath use - so do I
then lose that efficiency?

And out of curiosity, why does XPathDocument eat all of the whitespace?
Because xml schemes like Excel's SpreadsheetML need it.

--
thanks - dave
"Chris Lovett" wrote:
I'm on the .net xml team and I know for sure that once you've loaded an
XmlDocument without preserveWhitesp ace, you have lost all insignificant
whitespace information and there is no way for the XPathNavigator to
"reinvent" it on the fly. Therefore you'll have to tell folks who are
calling you not to do that. Or you chould change your component design
so
that they call you to load the XML that way you can be in control of how
the
whitespace processing happens.

"David Thielen" <th*****@nospam .nospam> wrote in message
news:71******** *************** ***********@mic rosoft.com...
> Hi;
>
> It's not my xml. I have a library that other people call and pass me
> their
> xml. I wrote all of my code using XPathDocument & XPathNavigator
> because
> it
> is the "suggested" approach.
>
> But I need to have whitespace preserved. There must be a way as
> Microsoft
> suggests using this approach and not using XmlDocument at all. Could
> you
> please ask the .net team? I find it hard to believe they would not have
> made
> it possible to do this.
>
> --
> thanks - dave
>
>
> "Kevin Yu [MSFT]" wrote:
>
>> Hi dave,
>>
>> There is no way to preserve whitespace in the code directly with
>> XPathNavigator. You can try to do the following:
>>
>> 1. Add whiteSpace="pre serve" in the tag. <space whiteSpace="pre serve">
>> </space>
>> 2. If the node is a whitespace, check the XPathNavigator. NodeType
>> property,
>> it has to be XPathNodeType.S ignificantWhite space or
>> XPathNodeType.W hitespace.
>>
>> Kevin Yu
>> =======
>> "This posting is provided "AS IS" with no warranties, and confers no
>> rights."
>>
>>


Nov 12 '05 #8
Yes - thank you.

I didn't see it for XPathDocument because the Stream ctor doesn't have that
option. But I can use the Stream to create an XmlDocument, Load it with the
Stream, then pass an XmlNodeReader.

--
thanks - dave
"Chris Lovett" wrote:
XPathDocument (and XmlDocument) default to preserveWhitesp ace=false for
backward compatibility reasons.

But you can tell both of these to preservice whitespace as follows:

new XPathDocument(@ "..\\..\\xmlfil e1.xml", XmlSpace.Preser ve);

and
XmlDocument xdoc = new XmlDocument();
xdoc.PreserveWh itespace = true;
"David Thielen" <th*****@nospam .nospam> wrote in message
news:8F******** *************** ***********@mic rosoft.com...
Hello;

First off, thank you for answering. Getting a definite no helps as then I
know that I'm not missing something.

Most cases I am passed a Stream so I can call new XmlDocument(Str eam)
instead of new XPathDocument(S tream). But all of the documentation I have
read says that XPathDocument is a lot faster for heavy xpath use - so do I
then lose that efficiency?

And out of curiosity, why does XPathDocument eat all of the whitespace?
Because xml schemes like Excel's SpreadsheetML need it.

--
thanks - dave
"Chris Lovett" wrote:
I'm on the .net xml team and I know for sure that once you've loaded an
XmlDocument without preserveWhitesp ace, you have lost all insignificant
whitespace information and there is no way for the XPathNavigator to
"reinvent" it on the fly. Therefore you'll have to tell folks who are
calling you not to do that. Or you chould change your component design
so
that they call you to load the XML that way you can be in control of how
the
whitespace processing happens.

"David Thielen" <th*****@nospam .nospam> wrote in message
news:71******** *************** ***********@mic rosoft.com...
> Hi;
>
> It's not my xml. I have a library that other people call and pass me
> their
> xml. I wrote all of my code using XPathDocument & XPathNavigator
> because
> it
> is the "suggested" approach.
>
> But I need to have whitespace preserved. There must be a way as
> Microsoft
> suggests using this approach and not using XmlDocument at all. Could
> you
> please ask the .net team? I find it hard to believe they would not have
> made
> it possible to do this.
>
> --
> thanks - dave
>
>
> "Kevin Yu [MSFT]" wrote:
>
>> Hi dave,
>>
>> There is no way to preserve whitespace in the code directly with
>> XPathNavigator. You can try to do the following:
>>
>> 1. Add whiteSpace="pre serve" in the tag. <space whiteSpace="pre serve">
>> </space>
>> 2. If the node is a whitespace, check the XPathNavigator. NodeType
>> property,
>> it has to be XPathNodeType.S ignificantWhite space or
>> XPathNodeType.W hitespace.
>>
>> Kevin Yu
>> =======
>> "This posting is provided "AS IS" with no warranties, and confers no
>> rights."
>>
>>


Nov 12 '05 #9
Hi there,

I have the same issue, but even if I use XmlDocument and set the
..PreserveWhite space to true, whe I deserialize the xml, this node comes with
null value.

Christian Llanos
"David Thielen" wrote:
Yes - thank you.

I didn't see it for XPathDocument because the Stream ctor doesn't have that
option. But I can use the Stream to create an XmlDocument, Load it with the
Stream, then pass an XmlNodeReader.

--
thanks - dave
"Chris Lovett" wrote:
XPathDocument (and XmlDocument) default to preserveWhitesp ace=false for
backward compatibility reasons.

But you can tell both of these to preservice whitespace as follows:

new XPathDocument(@ "..\\..\\xmlfil e1.xml", XmlSpace.Preser ve);

and
XmlDocument xdoc = new XmlDocument();
xdoc.PreserveWh itespace = true;
"David Thielen" <th*****@nospam .nospamwrote in message
news:8F******** *************** ***********@mic rosoft.com...
Hello;
>
First off, thank you for answering. Getting a definite no helps as then I
know that I'm not missing something.
>
Most cases I am passed a Stream so I can call new XmlDocument(Str eam)
instead of new XPathDocument(S tream). But all of the documentation I have
read says that XPathDocument is a lot faster for heavy xpath use - so do I
then lose that efficiency?
>
And out of curiosity, why does XPathDocument eat all of the whitespace?
Because xml schemes like Excel's SpreadsheetML need it.
>
--
thanks - dave
>
>
"Chris Lovett" wrote:
>
>I'm on the .net xml team and I know for sure that once you've loaded an
>XmlDocument without preserveWhitesp ace, you have lost all insignificant
>whitespace information and there is no way for the XPathNavigator to
>"reinvent" it on the fly. Therefore you'll have to tell folks who are
>calling you not to do that. Or you chould change your component design
>so
>that they call you to load the XML that way you can be in control of how
>the
>whitespace processing happens.
>>
>"David Thielen" <th*****@nospam .nospamwrote in message
>news:71******* *************** ************@mi crosoft.com...
Hi;
>
It's not my xml. I have a library that other people call and pass me
their
xml. I wrote all of my code using XPathDocument & XPathNavigator
because
it
is the "suggested" approach.
>
But I need to have whitespace preserved. There must be a way as
Microsoft
suggests using this approach and not using XmlDocument at all. Could
you
please ask the .net team? I find it hard to believe they would not have
made
it possible to do this.
>
--
thanks - dave
>
>
"Kevin Yu [MSFT]" wrote:
>
>Hi dave,
>>
>There is no way to preserve whitespace in the code directly with
>XPathNavigator . You can try to do the following:
>>
>1. Add whiteSpace="pre serve" in the tag. <space whiteSpace="pre serve">
></space>
>2. If the node is a whitespace, check the XPathNavigator. NodeType
>property,
>it has to be XPathNodeType.S ignificantWhite space or
>XPathNodeType. Whitespace.
>>
>Kevin Yu
>=======
>"This posting is provided "AS IS" with no warranties, and confers no
>rights."
>>
>>
>>
>>
>>
Jun 27 '08 #10

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

Similar topics

1
4007
by: Dave | last post by:
Is it possible to get <codes><code id="4"><name>abc</name></code></codes from the XML below in single SelectSingleNode/xPath expression step OR is going to have to be a multi=step process of using SelectNodes with an XPath expression to return all the nodes with "code id = 4", iterate the NodeList, re-build the XML string and wrap it with "<codes>" again? I wasn't sure if you can somehow return the parent node when using xPath to find...
2
1194
by: John A Grandy | last post by:
has anyone seen a situation similar to the following ? <level1 > <level2 > <level3 anAttribute="value3" /> </level2> </level1> Dim filePath As String Dim node As XMLNode
1
1854
by: David Thielen | last post by:
Hi; How do I handle the following: XPathNavigator nav = ...; String str = nav.SelectSingleNode("floats/@ok").Value; // works fine - returns 1.3 nav.SelectSingleNode("floats/@ok == 1.3"); // throws an exception
7
1912
by: David Thielen | last post by:
Hi; This code is in J# so it looks a little weird but you could change it to C# in a couple of seconds. The problem here is a single space node returns as an empty node: public static void main(String args) throws Exception {
1
4793
by: Jesper | last post by:
Hi, I've read somewhere that try/catch shoudn't be used as an alternative to if clauses (maybe it was in C++ regi). However, when using XmlNode.SelectSingleNode(XPath expression) to get a node, it throws an exception instead of returning null if the node doesn't excist. I'm a bit tentative to use a catch statement to handle this as this is not in my program considered a severe error. Is my conception of try/catch in C# wrong in...
1
7531
by: | last post by:
Hi, How can I make the XPath case INsensitive for SelectSingleNode()? Thanks.
3
1291
by: David Thielen | last post by:
Hi; Two questions. I have an XPathNavigator object where it's OuterXml property is "<jan>231</jan>" and I am trying to write an xpath statement that will return the "jan". XPathNavigator nav = ...; 1) I can do nav.Evaluate("name(parent::*)"); and get "month". But if I do nav.Evaluate("name(self::*)"); I get "" returned. Shouldn't I get "jan"?
3
7449
by: =?Utf-8?B?bmVlZDJzY3ViYQ==?= | last post by:
I have the following code snipet: .... _xmldocManifest.Load(strManifestAbsolutePath) Dim manifestNSManager As XmlNamespaceManager = New XmlNamespaceManager(_xmldocManifest.NameTable) manifestNSManager.AddNamespace(String.Empty, "http://www.imsproject.org/xsd/imscp_rootv1p1p2") manifestNSManager.AddNamespace("ns",
2
4543
by: =?Utf-8?B?Tm9yZW1hYw==?= | last post by:
Hi. Using VS2005, .NET 2.0. I have an xml document that I want to go through and set the values on attributes of elements. The elements are complex types defined in my schema (xsd) files. I can iterate the document and get my XmlType and XmlBaseType values just fine. However, as soon as I call SetValue to write to an attribute, the
0
9699
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
9562
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10305
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...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7598
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
6838
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
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
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
3792
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.