473,748 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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


XslCompiledTran sform xslt = new XslCompiledTran sform();

ASCIIEncoding encodeToByteArr ay = new ASCIIEncoding() ;
MemoryStream inputStream = new MemoryStream();
MemoryStream outputStream = new MemoryStream();
MemoryStream xslStream = new MemoryStream();

String inputString = "<foo>Hello XSL</foo>";
byte[] inputArray =
encodeToByteArr ay.GetBytes(inp utString);
//write the string buffer to the stream
inputStream.Wri te(inputArray, 0, inputString.Len gth);

String xslString = "<xsl:styleshee t
xmlns:xsl=\"htt p://www.w3.org/1999/XSL/Transform\"
version=\"1.0\" ><xsl:templat e match=\"foo\">< out><xsl:value-of
select=\".\"/></out></xsl:template></xsl:stylesheet> ";
byte[] xslArray = encodeToByteArr ay.GetBytes(xsl String);

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

xslt.Load(xslSt ream); <-- exception here

what's wrong?

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

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

xslStream.Write (xslArray, 0, xslString.Lengt h);

xslStream.Seek( 0, SeekOrigin.Begi n);

xslt.Load(xslSt ream); <-- exception here

tony wrote:
XslCompiledTran sform xslt = new XslCompiledTran sform();

ASCIIEncoding encodeToByteArr ay = new ASCIIEncoding() ;
MemoryStream inputStream = new MemoryStream();
MemoryStream outputStream = new MemoryStream();
MemoryStream xslStream = new MemoryStream();

String inputString = "<foo>Hello XSL</foo>";
byte[] inputArray =
encodeToByteArr ay.GetBytes(inp utString);
//write the string buffer to the stream
inputStream.Wri te(inputArray, 0, inputString.Len gth);

String xslString = "<xsl:styleshee t
xmlns:xsl=\"htt p://www.w3.org/1999/XSL/Transform\"
version=\"1.0\" ><xsl:templat e match=\"foo\">< out><xsl:value-of
select=\".\"/></out></xsl:template></xsl:stylesheet> ";
byte[] xslArray = encodeToByteArr ay.GetBytes(xsl String);

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

xslt.Load(xslSt ream); <-- exception here

what's wrong?

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

ASCIIEncoding encodeToByteArr ay = new ASCIIEncoding() ;
MemoryStream inputStream = new MemoryStream();
MemoryStream outputStream = new MemoryStream();
MemoryStream xslStream = new MemoryStream();

String inputString = "<foo>Hello XSL</foo>";
byte[] inputArray =
encodeToByteArr ay.GetBytes(inp utString);
//write the string buffer to the stream
inputStream.Wri te(inputArray, 0, inputString.Len gth);

String xslString = "<xsl:styleshee t
xmlns:xsl=\"htt p://www.w3.org/1999/XSL/Transform\"
version=\"1.0\" ><xsl:templat e match=\"foo\">< out><xsl:value-of
select=\".\"/></out></xsl:template></xsl:stylesheet> ";
byte[] xslArray = encodeToByteArr ay.GetBytes(xsl String);

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

xslt.Load(xslSt ream); <-- 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(XmlRe ader.Create(new StringReader(xs lString)));
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
2839
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
3761
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 a PHP page and the problem has to do with an auto-inserted "input" element, I'll post it here, too. I'd appreciate any advice, commentary, or even pessimistic sympathy if I'm just SOL. - Thanks. I am pasting some code below that I am having a...
0
2030
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 problems. I will outline the problem, what I have tried to do to fix it, and what I think caused it. Hope you can help and I am sorry this is long. The problem: I can't login to mysql anymore with the "root" username (which is where I have all...
2
2884
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 get around what seems like a bug in the dotnet framework? Scott Emick
1
5756
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 ideas what may be wrong? The stylesheet: <?xml version="1.0" encoding="utf-8"?> <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:output indent="yes"/>
0
2416
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 Regards Param
3
35072
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 Dim objFile As FileStream = Nothing objStream = New MemoryStream()
11
3892
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 element is missing" -- even though in Notepad the file looks normal. Has anybody ever seen this? Any clues? I have not been able to reproduce it on my computer. In general, when they e-mail me the files, the files arrive perfectly normal. ...
0
9370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9247
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8242
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.