c# - Transform XML returned from a web request using XLST -
i see several questions close none cover it:
- how apply xslt stylesheet in c#
- xslt transform of xml using xml data web form
- how transform xml structure generated request web services
i can cobble these worry passing through many steps efficient.
what have this, read xml http web request:
webrequest request = webrequest.create(url); webresponse response = request.getresponse(); stream stream = response.getresponsestream(); streamreader streamreader = new streamreader(stream); string xml = streamreader.readtoend();
this before need apply xlst transform needed. have (possibly null) xslcompiledtransform
object.
so want add block like:
if(transform != null) { xml = transform.transform(xml); }
clearly isn't possible written. see stringreaders , xmlreaders can created inefficient xml string , push object? can use stream
or streamreader
objects directly support same basic flow, optional transformation?
personally i'd use xmldocument.load()
function load xml url, without using webrequest
in case.
you can pass xmldocument
straight xslcompiledtransform.transform()
then.
xmldocument doc = new xmldocument(); doc.load(url); if (transform != null) { xmldocument tempdoc = new xmldocument(); using (xmlwriter writer = tempdoc.createnavigator().appendchild()) { transform.transform(doc, writer); } doc = tempdoc; } //use xmldocument transformed output
Comments
Post a Comment