Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to specify output method for xmlwriter 1

Status
Not open for further replies.

gacaccia

Technical User
May 15, 2002
258
US
i have an program where i'm extracting xml from comments in a vbs file and then i need to output an html file using an xsl file for the transformation. to that end, i have code of...

Code:
XslCompiledTransform transformer = new XslCompiledTransform();
transformer.Load(xslFile);
string xmlContent = ParseXMLFromFile(vbsFile);
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(xmlContent);
XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
settings.Indent = true;
transformer.Transform(xdoc.CreateNavigator(), XmlWriter.Create(htmlFile, settings));

my problem is that the output html tags are getting collapsed, which while appropriate for xml, is not appropriate for html and results in page display problems. for example, part of the output should include

Code:
<script type="text/javascript" src="source.js"></script>

however, the actual output looks like

Code:
<script type="text/javascript" src="source.js" />

i can fix this by putting in a hard-coded space or new line character, but it seems like i should be able to somehow direct the xmlwriter to not collapse end tags. i know that the xmlwritersettings class has a property for output method, but it appears to be read-only!? how do i tell the xmlwriter to output html?

thanks,

glenn
 
if the output method is readonly then there is either a ctor arguement or factory member to set the output method. one other option is this property is overridden by sub classes.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
If you want to preserve the output settings of the the xslt processor implementation and that you want to stream the output to XmlWriter, you can pass the OutputSettings of the processor directly to XmlWriterSettings. Like this.
[tt]
XslCompiledTransform transformer = new XslCompiledTransform();
transformer.Load(xslFile);
string xmlContent = ParseXMLFromFile(vbsFile);
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(xmlContent);
[red]//[/red]XmlWriterSettings settings = new XmlWriterSettings();
[red]//[/red]settings.OmitXmlDeclaration = true;
[red]//[/red]settings.Indent = true;
transformer.Transform(xdoc.CreateNavigator(), XmlWriter.Create(htmlFile, [red]transformer.OutputSettings[/red]));
[/tt]
Those settings OmitXmlDeclaration and Indent can naturally be set in the xsl document, if you have any concern on those settings.
[tt] <xsl:eek:utput method="html" indent="yes" omit-xml-declaration="yes" />[/tt]
 
tsuji, that is exactly what i needed. using transformer.outputsettings, i'm able to specify HTML output and my closing tags are no longer getting collapsed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top