469,323 Members | 1,567 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

Convert XmlDocument to XpathDocument

Hi,

I've an object of XmlDocument, I need to pass it to some function which
takes XpathDocument object, How could I convert? There is not Conversion
Operator overload like that.

Your reply might help me a lot.

Thanks,
Fahad
Nov 12 '05 #1
5 11771


Fahad Ashfaque wrote:
I've an object of XmlDocument, I need to pass it to some function which
takes XpathDocument object, How could I convert? There is not Conversion
Operator overload like that.


You can save to a MemoryStream and then load from that stream e.g.
MemoryStream memStream = new MemoryStream();
xmlDocument.Save(memStream);
memStream.Position = 0;
XPathDocument xPathDocument = new XPathDocument(memStream);

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
but that would be parsed again would not that be ?

My document is 3 MB of size and it takes 4 Seconds for XmlDocument.Load()
to return.

Dont I have other choice ?

"Martin Honnen" wrote:


Fahad Ashfaque wrote:
I've an object of XmlDocument, I need to pass it to some function which
takes XpathDocument object, How could I convert? There is not Conversion
Operator overload like that.


You can save to a MemoryStream and then load from that stream e.g.
MemoryStream memStream = new MemoryStream();
xmlDocument.Save(memStream);
memStream.Position = 0;
XPathDocument xPathDocument = new XPathDocument(memStream);

--

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

Nov 12 '05 #3


Fahad Ashfaque wrote:
but that would be parsed again would not that be ?

My document is 3 MB of size and it takes 4 Seconds for XmlDocument.Load()
to return.

Dont I have other choice ?


Why do you start with an XmlDocument at all?
Which is the method you want to pass the document to, perhaps it has
some overload with a signature for an interface XmlDocument implements.
It is difficult to make suggestions without knowing more context.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #4
I need to pass it to XslTransform and get the output through StreamWriter.
"Martin Honnen" wrote:


Fahad Ashfaque wrote:
but that would be parsed again would not that be ?

My document is 3 MB of size and it takes 4 Seconds for XmlDocument.Load()
to return.

Dont I have other choice ?


Why do you start with an XmlDocument at all?
Which is the method you want to pass the document to, perhaps it has
some overload with a signature for an interface XmlDocument implements.
It is difficult to make suggestions without knowing more context.

--

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

Nov 12 '05 #5


Fahad Ashfaque wrote:
I need to pass it to XslTransform and get the output through StreamWriter.


XslTransform has a method Load that takes an IXPathNavigable which is
implemented by both XPathDocument as well as XmlDocument.
And the method Transform also takes an IXPathNavigable so there you can
pass in an XmlDocument as well.
So when using XslTransform there is no need to convert an XmlDocument to
an XPathDocument.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ian Lawton | last post: by
1 post views Thread by John A Grandy | last post: by
2 posts views Thread by Graham Pengelly | last post: by
1 post views Thread by vikram | last post: by
3 posts views Thread by Fahad Ashfaque | last post: by
1 post views Thread by Greg Allen | last post: by
5 posts views Thread by Ben R. | last post: by
5 posts views Thread by =?Utf-8?B?TWFyaw==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.