Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
XmlSerializer
Message
From
03/06/2005 04:26:58
 
 
To
02/06/2005 15:11:46
Keith Payne
Technical Marketing Solutions
Florida, United States
General information
Forum:
ASP.NET
Category:
XML
Title:
Miscellaneous
Thread ID:
01018060
Message ID:
01019722
Views:
21
>The variable streamWriter is declared as a stream, not a stream writer. It's not an error per se, but I thought that it might have contributed to the confusion. For testing, it is probably best to stick with one of the derived stream classes instead of System.IO.Stream or System.IO.StreamWriter. When you are ready to perform the transformation, you can attach a writer to the stream, or you can transform the stream itself and attach a writer afterwards.

I know, it was clumsy of me naming it streamWriter, but I'm aware that it is a stream. I just can't figure out what class I should use, and I don't really think that is the problem either.

>
>System.IO.Stream is an abstract class. As far as I can infer from the documentation, a System.IO.Stream has no backing store. You have to use one of the derived types to make it useful.
>
System.IO.MemoryStream streamWriter = (System.IO.MemoryStream) req.GetRequestStream();
>
>Since the MemoryStream is already working but showing blanks, I'd look to the XSL file as the likely source of possible errors.
>
That line of code won't work because the cast to MemoryStream is invalid. As far as XSL goes, it has to be correct, as writing to a file goes just fine.

The essence of the problem seems to be that using XslTransform.Transform() with XmlTextWriter object as the fourth param works fine, but any kind of stream just won't work.

This is what the problem boils down to
// 1. Create a HttpWebRequest and get the RequestStream object (Works)
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(RemoteServiceURI);
Stream httpStream = req.GetRequestStream();

// 2. Create XMLSerializer for object (Works)
XmlSerializer xmltrans = new XmlSerializer(typeof(PaymentContainer),extraTypes);

// 3. Create memory stream for object serialization (Works)
MemoryStream memStream = new MemoryStream();

// 4. Serialize (Works)
xmltrans.Serialize(memStream ,Payment);
memStream.Seek(0, SeekOrigin.Begin);

// 5. Create and load XML and XSL documents (Works)
XPathDocument myXPathDocument = new XPathDocument(memStream);
XslTransform myXslTransform = new XslTransform();
myXslTransform.Load(xsltDoc);

// 6.(ALT 1) Create XmlTextWriter and call XSL.Transform() with it (Works)
XmlTextWriter xwriter = new XmlTextWriter(xsltTestDoc , null);
myXslTransform.Transform(myXPathDocument, null, xwriter, null);
xwriter.Close();

// 6.(ALT 2) Call XSL.Transform() with the stream object from step 1 (NO GOOD!)
myXslTransform.Transform(myXPathDocument, null, httpStream, null);

// 6.(ALT 3) Create MemoryStream to use in Transform and examine contents (charArray has correct length, but all empty)
MemoryStream memStreamToSend = new MemoryStream();
myXslTransform.Transform(myXPathDocument, null, memStreamToSend, null);
memStreamToSend.Seek(0, SeekOrigin.Begin);
byte[] byteArray = new byte[memStreamToSend.Length];
int count = memStreamToSend.Read(byteArray, 0, (int) memStreamToSend.Length);
UnicodeEncoding uniEncoding = new UnicodeEncoding();
char[] charArray = new char[uniEncoding.GetCharCount(byteArray, 0, count)];
Am I confused? You bet!
Danijel
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform