×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

how to specify output method for xmlwriter

how to specify output method for xmlwriter

how to specify output method for xmlwriter

(OP)
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
 

RE: how to specify output method for xmlwriter

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: Database Connection Management

RE: how to specify output method for xmlwriter

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.

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, transformer.OutputSettings));

Those settings OmitXmlDeclaration and Indent can naturally be set in the xsl document, if you have any concern on those settings.
    <xsl:output method="html" indent="yes" omit-xml-declaration="yes" />

RE: how to specify output method for xmlwriter

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close