473,464 Members | 1,623 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

OuterXml from XPathNavitor in .NET 1.1

I am come to rely on the following pattern to get the XML of a selected
pattern with .NET 2.0

Dim xmlDocument As XPathDocument = New XPathDocument(xmlReader)
Dim navigator As XPathNavigator = xmlDocument.CreateNavigator()
Dim nodes As XPathNodeIterator = navigator.Select(queryString)
If nodes IsNot Nothing AndAlso nodes.Count 0 Then
Dim sb As System.Text.StringBuilder = New
System.Text.StringBuilder
While nodes.MoveNext()
sb.Append(nodes.Current.OuterXml)
End While
End If

But now I am forced back to .NET 1.1 and it seems that OuterXml is not
available. How can I acheive the same thing with .NET 1.1? I see in the
documentation that I can cast the navigator to IHasXmlNode and then get an
XmlNode from that cast. But the documentation indicates that this is only
valid for navigators created from XmlDocument not XPathDocument. Any
suggestions?

Kevin

Sep 6 '06 #1
6 1860
I think this could be for you.

"Kevin Burton" <Ke*********@discussions.microsoft.comwrote in message
news:47**********************************@microsof t.com...
>I am come to rely on the following pattern to get the XML of a selected
pattern with .NET 2.0

Dim xmlDocument As XPathDocument = New XPathDocument(xmlReader)
Dim navigator As XPathNavigator = xmlDocument.CreateNavigator()
Dim nodes As XPathNodeIterator = navigator.Select(queryString)
If nodes IsNot Nothing AndAlso nodes.Count 0 Then
Dim sb As System.Text.StringBuilder = New
System.Text.StringBuilder
While nodes.MoveNext()
sb.Append(nodes.Current.OuterXml)
End While
End If

But now I am forced back to .NET 1.1 and it seems that OuterXml is not
available. How can I acheive the same thing with .NET 1.1? I see in the
documentation that I can cast the navigator to IHasXmlNode and then get an
XmlNode from that cast. But the documentation indicates that this is only
valid for navigators created from XmlDocument not XPathDocument. Any
suggestions?

Kevin

Sep 7 '06 #2


Kevin Burton wrote:
I am come to rely on the following pattern to get the XML of a selected
pattern with .NET 2.0

Dim xmlDocument As XPathDocument = New XPathDocument(xmlReader)
Dim navigator As XPathNavigator = xmlDocument.CreateNavigator()
Dim nodes As XPathNodeIterator = navigator.Select(queryString)
If nodes IsNot Nothing AndAlso nodes.Count 0 Then
Dim sb As System.Text.StringBuilder = New
System.Text.StringBuilder
While nodes.MoveNext()
sb.Append(nodes.Current.OuterXml)
End While
End If

But now I am forced back to .NET 1.1 and it seems that OuterXml is not
available. How can I acheive the same thing with .NET 1.1? I see in the
documentation that I can cast the navigator to IHasXmlNode and then get an
XmlNode from that cast. But the documentation indicates that this is only
valid for navigators created from XmlDocument not XPathDocument.
Well start your code with e.g.
Dim xml_Document as New System.Xml.XmlDocument()
xml_Document.Load(xmlReader)
Dim navigator As XPathNavigator = xml_Document.CreateNavigator()
and then continue as needed, when you have are iterating cast to
IHasXmlNode and take the OuterXml.
Or simply use
For Each Node As XmlNode In xml_Document.SelectNodes(querystring)
' use Node.OuterXml
Next
no need to use the navigator API if you operate on an XmlDocument.

If you want to use an XPathDocument then you will either need to
implement the serialization to XML yourself or for instance look into
XPathNavigatorReader in <http://mvp-xml.sourceforge.net/api/>.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 7 '06 #3
Thank you this was very helpful.

In interest of simplicity I agree that I would like to drop XPathNavigator
and just use XmlDocument.SelectNodes. But, there is a reason that I am
hanging on to XPathNavigator. I need to associate a namespace with the query
for nodes, like:

Dim nsMgr As New XmlNamespaceManager(navigator.NameTable)
nsMgr.AddNamespace("t", "http://www.temp/xsd")
Dim expression As XPathExpression =
navigator.Compile(String.Format("//t:{0}", queryString))
expression.SetContext(nsMgr)
SelectNodes = navigator.Select(expression)

Can make XmlDocument select the nodes taking in consideration of the
namespace? If so how?

Thank you.

Kevin

"Martin Honnen" wrote:
>

Kevin Burton wrote:
I am come to rely on the following pattern to get the XML of a selected
pattern with .NET 2.0

Dim xmlDocument As XPathDocument = New XPathDocument(xmlReader)
Dim navigator As XPathNavigator = xmlDocument.CreateNavigator()
Dim nodes As XPathNodeIterator = navigator.Select(queryString)
If nodes IsNot Nothing AndAlso nodes.Count 0 Then
Dim sb As System.Text.StringBuilder = New
System.Text.StringBuilder
While nodes.MoveNext()
sb.Append(nodes.Current.OuterXml)
End While
End If

But now I am forced back to .NET 1.1 and it seems that OuterXml is not
available. How can I acheive the same thing with .NET 1.1? I see in the
documentation that I can cast the navigator to IHasXmlNode and then get an
XmlNode from that cast. But the documentation indicates that this is only
valid for navigators created from XmlDocument not XPathDocument.

Well start your code with e.g.
Dim xml_Document as New System.Xml.XmlDocument()
xml_Document.Load(xmlReader)
Dim navigator As XPathNavigator = xml_Document.CreateNavigator()
and then continue as needed, when you have are iterating cast to
IHasXmlNode and take the OuterXml.
Or simply use
For Each Node As XmlNode In xml_Document.SelectNodes(querystring)
' use Node.OuterXml
Next
no need to use the navigator API if you operate on an XmlDocument.

If you want to use an XPathDocument then you will either need to
implement the serialization to XML yourself or for instance look into
XPathNavigatorReader in <http://mvp-xml.sourceforge.net/api/>.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 7 '06 #4
"Kevin Burton" <Ke*********@discussions.microsoft.comwrote in message
news:18**********************************@microsof t.com...
Thank you this was very helpful.

In interest of simplicity I agree that I would like to drop XPathNavigator
and just use XmlDocument.SelectNodes. But, there is a reason that I am
hanging on to XPathNavigator. I need to associate a namespace with the
query
for nodes, like:

Dim nsMgr As New XmlNamespaceManager(navigator.NameTable)
nsMgr.AddNamespace("t", "http://www.temp/xsd")
Dim expression As XPathExpression =
navigator.Compile(String.Format("//t:{0}", queryString))
expression.SetContext(nsMgr)
SelectNodes = navigator.Select(expression)

Can make XmlDocument select the nodes taking in consideration of the
namespace? If so how?
Just use document.SelectNodes(xpath, nsMgr).

John
Sep 7 '06 #5


Kevin Burton wrote:

But, there is a reason that I am
hanging on to XPathNavigator. I need to associate a namespace with the query
for nodes, like:

Dim nsMgr As New XmlNamespaceManager(navigator.NameTable)
nsMgr.AddNamespace("t", "http://www.temp/xsd")
Dim expression As XPathExpression =
navigator.Compile(String.Format("//t:{0}", queryString))
expression.SetContext(nsMgr)
SelectNodes = navigator.Select(expression)
You simply need e.g.

Dim doc as New XmlDocument()
doc.Load("file.xml")
Dim nsMgr As New XmlNamespaceManager(doc.NameTable)
nsMgr.AddNamespace("t", "http://www.temp/xsd")
Dim nodeList as XmlNodeList = _
doc.SelectNodes(String.Format("//t:{0}", queryString), nsMgr)
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 7 '06 #6
Sorry, here goes the url: http://www.tkachenko.com/blog/archives/000155.html
"Mauricio Grimberg" <mg******@hotmail.comwrote in message
news:es**************@TK2MSFTNGP06.phx.gbl...
>I think this could be for you.

"Kevin Burton" <Ke*********@discussions.microsoft.comwrote in message
news:47**********************************@microsof t.com...
>>I am come to rely on the following pattern to get the XML of a selected
pattern with .NET 2.0

Dim xmlDocument As XPathDocument = New XPathDocument(xmlReader)
Dim navigator As XPathNavigator = xmlDocument.CreateNavigator()
Dim nodes As XPathNodeIterator = navigator.Select(queryString)
If nodes IsNot Nothing AndAlso nodes.Count 0 Then
Dim sb As System.Text.StringBuilder = New
System.Text.StringBuilder
While nodes.MoveNext()
sb.Append(nodes.Current.OuterXml)
End While
End If

But now I am forced back to .NET 1.1 and it seems that OuterXml is not
available. How can I acheive the same thing with .NET 1.1? I see in the
documentation that I can cast the navigator to IHasXmlNode and then get
an
XmlNode from that cast. But the documentation indicates that this is only
valid for navigators created from XmlDocument not XPathDocument. Any
suggestions?

Kevin


Sep 7 '06 #7

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

Similar topics

1
by: Adam Smith | last post by:
When you do this: public void someMethod(Xmldocument xml) { XmlDocument localxml = new XmlDocument(); localxml.LoadXml(xml.OuterXml); } Are you getting all the data in localxml? I want to...
3
by: Henrik K | last post by:
Selecting element nodes from a xmlDataDocument using the childNodes collection or by using selectSingleNode and then reading innerXml or outerXml leaks cpu-resources. A trivial example showing...
1
by: ryang | last post by:
Hi, I am trying to randomly select a element in a DOM tree, use the OuterXml property for XmlElement to display the XML content of the element and its children. However, XmlElement.OuterXml...
3
by: KJ | last post by:
It is true that there is no way to get the outerXml of XPathNodeIterator.Current? Please say it isn't so.
0
by: Tom S. | last post by:
..Net Framework 1.1 Version 1.1.4322 SP1 WinXP SP2 MS Dev Environment 2003 Version 7.1.3088 ( Visual Studio 2003 ) I have an xml document that I only use a portion of. Since the xml document...
0
by: mark | last post by:
For ease of example i have cutt down what i need to do to the following I have an xml file with 2 attributes, firstname and lastname I have a database with the same 2 columns what i need to...
0
by: nano2k | last post by:
Hi Is it possible to find out the output size of an XmlDocument object? I mean, a good-enough approach is this: XmlDocument doc = new XmlDocument(); // load data in doc int length =...
1
by: CindyH | last post by:
Hi I'm not sure whether I should send this as a new message or use the one I've been using but... I'm using vb.net 2.0 - My problem is I need to send something like this: 'dim encodedstring =...
6
by: CindyH | last post by:
Hi I'm not sure whether I should send this as a new message or use the one I've been using but... I'm using vb.net 2.0 - My problem is I need to send something like this: 'dim encodedstring =...
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
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...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.