Sign in to follow this  

[.net] XmlDocument load problem

This topic is 4075 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to be able to do the following: 1)Load and xml file into a XmlDocument object. 2)Select a node within this document. 3)save the selected node to a memorystream. 4)load this memorystream into another XmlDocument object. I though this would be simple but oh how wrong I was!! If I create a new XmlDocument object and add the selected node to it. Then save this document to an .xml file. I can then load it into a new XmlDocument object. But if instead of saving to an .xml file, I save to a memorystream, it will not load back into a XmlDocument object, I just get a "Root element is missing" error! Note: I have saved the memorystream out to a text file and it is exactly the same as the .xml file saved from the XmlDocument. I am completely lost on how to get this to work.

Share this post


Link to post
Share on other sites
I am actually trying to get a new XmlDocument made up of the selected node. This is because I want to then transform it via xslt. The problem is that the xslt transform also complains of "Root node is missing". I thought by just loading it back into an XmlDocument I would loose some of the complexity and it would be easier to solve.

Share this post


Link to post
Share on other sites
I have solved it.

I have to say that it was not particularly obvious that this could be done but hey, it's done now.

I simply had to pas the XmlNode.CreateNavigator() in to the XmlCompiledTransform.Transform method.

I am still puzzeled as to why it didn't work from the memorystream though, but I think the way I found to do it is more efficient anyway.

Share this post


Link to post
Share on other sites
With the memory stream did you seek back to the beginning?

If you didnt then you could have had this

(Shoddy diagram)

<xml>Some random Node</xml>
^ current position of memory stream is at end of stream, so when you call


xmlDocument.Load(memoryStream);
its correct - there is no root element, because theres nothing after the current position in the stream.

So bewfore the load call try:

memoryStream.Seek(0,SeekOrigin.Begin);

and maybe that would work.

In theory anyways.......

N

Share this post


Link to post
Share on other sites

This topic is 4075 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this