it as it is the recomended API and a lot faster. But I have to get the actual
"Martin Honnen" wrote:
>
>
> David Thielen wrote:
>
>
> > The problem here is a single space node returns as an empty node:
> >
> > public static void main(String[] args) throws Exception
> > {
> >
> > XmlDocument doc = new XmlDocument();
> > doc.set_PreserveWhitespace(true);
> >
> > String xml = "<root><space> </space></root>";
> > Encoding encoder = Encoding.GetEncoding("utf-8");
> > doc.Load(new MemoryStream(encoder.GetBytes(xml)));
> >
> > XPathNavigator nav = new XPathDocument(new
> > XmlNodeReader(doc)).CreateNavigator();
> > nav = nav.SelectSingleNode("/root");
> > nav = nav.SelectSingleNode("./space");
> > String str = nav.get_Value();
> > int len = str.length();
> > System.out.println("value = {" + str + "}");
> > System.out.println("length = " + len);
> > }
>
> When I try the following C#
>
> string xmlMarkup = "<root><text> </text></root>";
>
> XmlDocument xmlDocument = new XmlDocument();
> xmlDocument.PreserveWhitespace = true;
> xmlDocument.LoadXml(xmlMarkup);
>
> XmlElement text = xmlDocument.SelectSingleNode(@"/root/text") as
> XmlElement;
> if (text != null) {
> Console.WriteLine("InnerText: '{0}', Length: {1}.",
> text.InnerText, text.InnerText.Length);
>
> XPathNavigator xPathNavigator = text.CreateNavigator();
> Console.WriteLine("Value: '{0}', Length: {1}",
> xPathNavigator.Value, xPathNavigator.Value.Length);
> }
>
> with .NET 2.0 Beta 2 I get the output
>
> InnerText: ' ', Length: 1.
> Value: ' ', Length: 1
>
> which seems fine to me, so maybe you can streamline your code.
>
> Or do you have specific needs to
> - create a memory stream from a string
> - load an XmlDocument from that memory stream
> - create a XmlNodeReader on that XmlDocument
> - create an XPathDocument on that XmlNodeReader
> - create an XPathNavigator from the XPathDocument
> when loadXml exists for the first two steps and the XPathNavigator can
> simply be created from an XmlNode?
>
>
> --
>
> Martin Honnen --- MVP XML
>
http://JavaScript.FAQTs.com/