Transform result into XmlDocument or XmlDataDocument

K

KemperR

Dear Experts,

I'm relatively new to asp.net 2.0 and need some help on a very easy
thing.
I would like to store the result of the transformation in an object for
further processing.
But it seems that the Transform method can not do this.
My code looks basically like the lines below.

XmlDocument xmlDoc = new XmlDocument();
XmlDocument xmlOut = new XmlDocument();
XslCompiledTransform transform = new XslCompiledTransform();

xmlDoc.Load("myXMLFile.xml")

transform.Load("MyXslFile.xsl");

transform.Transform(xmlDoc, (XsltArgumentList)null, xmlOut);

There is obviously no overload for XmlDocument (or XmlDataDocument) as
output.
Do I really need to write the output to a file ??!!
My final traget is to fill a tree with the xml result of the
translation.
Therefore I think, I need an XmlDocument object.

Any hint is highly welcome

Rolf
 
L

Luc E. Mistiaen

as one of the overload returns an XmlReader I guess you can do the
following:

xmlOut.Load (transform.Transform(xmlDoc, (XsltArgumentList)null, null));

/LM
 
K

KemperR

Dear Luc,

thank you for your quick feedback.
I tried your idea, but unfortunately it does not work.
I used both Load and LoadXml.
Load , I think has no chance as it expects a string.
LoadXml faild too.
Meantime I found a hint to utilise the stream overload.
So I assigned a MemoryStream object to the output.
This seems to work, but now I have to get the stream content into the
XmlDocument.
Up to now I could not succedd to do this ( which is clearly my poor
ability on .net 2.0)
Any idea how ?

Thanks

Rolf
 
L

Luc E. Mistiaen

I tried your idea, but unfortunately it does not work.
I used both Load and LoadXml.
Load , I think has no chance as it expects a string.
LoadXml faild too.

You have it reversed: LoadXml expect a string (Xml formatted) and Load
expect either a file name or a stream.
A stream (in this case an XmlReader) is one of the possible return value for
Transform.

What error do you get exactly. I have by now tried what I say and it works.
The only difference with what I suggested previously is that you have to
give a type to the third argument (to lift ambiguity when using null).

i.e. use
Target.Load (T.Transform (Source, null, (XmlUrlResolver) null)) ;

Also I use V1.1, but I don't think it make a difference in this case.

/LM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top