Forum main page
Most
active member
Login page
Register
Log out
Search page
View our event calendar
Add general event such as an
upcoming software release or conference
View all birthdays
Public image gallery
Upload your images in your profile
Profile editing page
Subscription list page
Address book page
Member list page
View the most
active member
User groups listing
Private message page
|
|
Users viewing this topic: none
|
|
Login | |
|
XslCompiledTransform and document() function - 16 July 2007
|
|
|
eholder
Posts: 4
Score: 0 Joined: 13 July 2007 Status: offline
|
XslCompiledTransform.Transform appears to be trying to validate documents I load indirectly via the document() function. I only want to validate my source XML document against my schema. My XSL code simply calls document("c:/RefDoc.xml") to look up data in an external table. I don't really want to validate RefDoc.xml, though I don't mind doing so if I can tell it which schema to use. Here is my code (C# 2.0): public class XsltTransform { private string m_schemaValidationErrors = ""; public XsltTransform() {} public void transform(string sourcePath, string schemaPath, string xsltPath, string resultPath) { try { // Set up an XmlReader to read the source XML document. XmlReaderSettings settings = new XmlReaderSettings(); settings.ConformanceLevel = ConformanceLevel.Auto; settings.IgnoreWhitespace = true; settings.IgnoreComments = true; // Removing the following 3 statements allows it to run w/o validation. settings.Schemas.Add(null, schemaPath); settings.ValidationType = ValidationType.Schema; settings.ValidationEventHandler += new ValidationEventHandler(settings_ValidationEventHandler); XmlReader reader = XmlReader.Create(sourcePath, settings); // Set up a processor to run the XSL transform. // Since the XSLT code uses the "document()" function, enable that. // Also, for the same reason, we need an XmlResolver. XsltSettings xsltSettings = new XsltSettings(); xsltSettings.EnableDocumentFunction = true; XmlUrlResolver xur = new XmlUrlResolver(); XslCompiledTransform myXslTransform = new XslCompiledTransform(); myXslTransform.Load(xsltPath, xsltSettings, xur); // Now, perform the transform. XmlTextWriter writer = new XmlTextWriter(resultPath, null); myXslTransform.Transform(reader, null, writer, xur); writer.Close(); } catch (Exception e) { System.Console.WriteLine(e); } } void settings_ValidationEventHandler(object sender, ValidationEventArgs e) { m_schemaValidationErrors += e.Message; } } The error I am getting is: System.Xml.Xsl.XslTransformException: An error occurred while loading document 'RefDoc.xml'. See InnerException for a complete description of the error. ---> System.Xml.Schema.XmlSchemaValidationException: The 'RefDocRoot' element is not declared.
|
|
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|