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

## 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 on other sites
Rather than serialising and deserialising the node you want, have you tried:
XmlNode.Clone ();

Skizz

##### 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 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 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

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

1. 1
Rutin
26
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 10
• 9
• 9
• 46
• 41
• ### Forum Statistics

• Total Topics
631750
• Total Posts
3002067
×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!