![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Is it possible to control the node style that XslTransform uses to output XML? |
|
but if I use the XslTransform class I get mySchema rdf:resource='fred'></mySchema Unfortunately, my RDF parser doesn't like the second form, |
|
if it's possible to tell XslTransform to use the shortened notation? |
#3
| |||
| |||
|
|
"Paul Hatcher" <phatcher (AT) spamless (DOT) cix.co.uk> wrote Is it possible to control the node style that XslTransform uses to output XML? Not directly on the XslTransform class, but there is a way (see below). : : but if I use the XslTransform class I get mySchema rdf:resource='fred'></mySchema Unfortunately, my RDF parser doesn't like the second form, This is a bug in the RDF parser. The Infoset represented by both serializations is identical. The reason XSLT doesn't address this is that the particulars of the XML syntax are irrelevant to the document's content (i.e., it doesn't matter whether double-quote or single-quote is used to delimit the attribute values, or empty tags are rendered one way or another). : : if it's possible to tell XslTransform to use the shortened notation? An XmlTextWriter can be wrapped around the output from XslTransform's Transform( ) method. This XmlTextWriter can intercept calls to the WriteFullEndElement( ) method, which XslTransform uses, and replace them with calls to WriteEndElement( ). WriteEndElement( ) will produce the shortened end tag when the element has no content. Here is the code, - - - XmlTextWriterEE.cs (complete) using System; using System.IO; using System.Xml; /// <summary /// Wrapper that forces shortened empty element end tags to /// be rendered when possible. /// </summary public class XmlTextWriterEE : XmlTextWriter { public XmlTextWriterEE( TextWriter sink) : base( sink) {;} public override void WriteFullEndElement() { base.WriteEndElement(); } } - - - The way this might work with an XslTransform, named transformerObj, would be to wrap some TextWriter (in this example, I wrap the Console output stream, i.e., stdout). transformerObj.Transform( xmlDoc.CreateNavigator, null, new XmlTextWriterEE( Console.Out) ); The XmlTextWriterEE silently intercepts calls that instruct it to write a full end tag (for instance, to be more compatible with HTML) and redirects them to the method that'll write out a shortened end tag for empty elements. Derek Harmon |
#4
| |||
| |||
|
|
Hi Is it possible to control the node style that XslTransform uses to output XML? I'm trying to convert a file from XML to RDF and if I do the transform in XmlSpy I get the following mySchema rdf:resource='fred' / but if I use the XslTransform class I get mySchema rdf:resource='fred'></mySchema Unfortunately, my RDF parser doesn't like the second form, so I want to know if it's possible to tell XslTransform to use the shortened notation? TIA Paul |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |