473,395 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

XslCompiledTransform Load method getting "Root element is missing" XSL Compile error...???


XslCompiledTransform xslt = new XslCompiledTransform();

ASCIIEncoding encodeToByteArray = new ASCIIEncoding();
MemoryStream inputStream = new MemoryStream();
MemoryStream outputStream = new MemoryStream();
MemoryStream xslStream = new MemoryStream();

String inputString = "<foo>Hello XSL</foo>";
byte[] inputArray =
encodeToByteArray.GetBytes(inputString);
//write the string buffer to the stream
inputStream.Write(inputArray, 0, inputString.Length);

String xslString = "<xsl:stylesheet
xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"
version=\"1.0\"><xsl:template match=\"foo\"><out><xsl:value-of
select=\".\"/></out></xsl:template></xsl:stylesheet>";
byte[] xslArray = encodeToByteArray.GetBytes(xslString);

//write the string buffer to the stream
xslStream.Write(xslArray, 0, xslString.Length);

xslt.Load(xslStream); <-- exception here

what's wrong?

here is xslString
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="foo">
<out><xsl:value-of select="."/></out>
</xsl:template>
</xsl:stylesheet>

Dec 7 '06 #1
2 8325
crap figured it out..i didn't reset the stream back to the beginning =P

xslStream.Write(xslArray, 0, xslString.Length);

xslStream.Seek(0, SeekOrigin.Begin);

xslt.Load(xslStream); <-- exception here

tony wrote:
XslCompiledTransform xslt = new XslCompiledTransform();

ASCIIEncoding encodeToByteArray = new ASCIIEncoding();
MemoryStream inputStream = new MemoryStream();
MemoryStream outputStream = new MemoryStream();
MemoryStream xslStream = new MemoryStream();

String inputString = "<foo>Hello XSL</foo>";
byte[] inputArray =
encodeToByteArray.GetBytes(inputString);
//write the string buffer to the stream
inputStream.Write(inputArray, 0, inputString.Length);

String xslString = "<xsl:stylesheet
xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"
version=\"1.0\"><xsl:template match=\"foo\"><out><xsl:value-of
select=\".\"/></out></xsl:template></xsl:stylesheet>";
byte[] xslArray = encodeToByteArray.GetBytes(xslString);

//write the string buffer to the stream
xslStream.Write(xslArray, 0, xslString.Length);

xslt.Load(xslStream); <-- exception here

what's wrong?

here is xslString
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="foo">
<out><xsl:value-of select="."/></out>
</xsl:template>
</xsl:stylesheet>
Dec 8 '06 #2
tony wrote:
XslCompiledTransform xslt = new XslCompiledTransform();

ASCIIEncoding encodeToByteArray = new ASCIIEncoding();
MemoryStream inputStream = new MemoryStream();
MemoryStream outputStream = new MemoryStream();
MemoryStream xslStream = new MemoryStream();

String inputString = "<foo>Hello XSL</foo>";
byte[] inputArray =
encodeToByteArray.GetBytes(inputString);
//write the string buffer to the stream
inputStream.Write(inputArray, 0, inputString.Length);

String xslString = "<xsl:stylesheet
xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"
version=\"1.0\"><xsl:template match=\"foo\"><out><xsl:value-of
select=\".\"/></out></xsl:template></xsl:stylesheet>";
byte[] xslArray = encodeToByteArray.GetBytes(xslString);

//write the string buffer to the stream
xslStream.Write(xslArray, 0, xslString.Length);

xslt.Load(xslStream); <-- exception here

what's wrong?
The whole approach witht those memory streams is cumbersome and
unnecessary. If you have a string with XML (or XSLT) then simply use a
StringReader over that string and pass the StringReader or XmlReader
over that StringReader to the method e.g.
xslt.Load(XmlReader.Create(new StringReader(xslString)));
You do not gain anything by wrestling with encodings, byte arrays and
streams, all those XML APIs consume XmlReader or even StringReader directly.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Dec 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: will | last post by:
All I am trying to pass a simple xml file using xmlspy : <?xml version="1.0" standalone="no"?> <inventory> <vehicle> <make>Chevy</make>
3
by: Jonathan | last post by:
Hi all: I originally posted this in an HTML forum, but have realized that the solution may (a) require a server-side change or (b) be non-existent. In any case, since the page I'm dealing with is...
0
by: damontimm | last post by:
My setup: Mac OS 10.4.4; mysql 4.x ... everything was installed and working fine for some time. Today, I added drupal to my system and had to create a new database in mysql -- now I am having some...
2
by: Scott Emick | last post by:
I am still having issues with getting Root Element Missing instead of the actual error that the webservice call is supposed to be returning. I'm using VB .Net 2003. Has anyone else been able to...
1
by: Tomas | last post by:
When I try to load my xslt i get an xml exception with the message "Root element is missing". The stylesheet works when I preview it in stylus studio, but apparently not in my application. Any...
0
by: sridhar | last post by:
hey friends i am trying to sign a message using x.509 certificate and i get the {"Malformed reference element."} error when calling ComputeSignature method.can any one help me on this please...
3
by: lisa.bogart | last post by:
I am getting a "Root element is missing" error when I try to load a stream into and XmlDocument. Can anyone help me with what I am doing wrong??? Dim xmlTextWriter As XmlTextWriter = Nothing...
11
by: MC | last post by:
I have a couple of customers who are using a program that deserializes an XML file, and on some files, the program fails to see the content of the file -- treats it as zero length and reports "root...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.