A little rant

  • Thread starter Thread starter camainc
  • Start date Start date
C

camainc

I'm just now migrating to the 2.0 framework, and in working with the
System.Xml namespace, it seems like almost every method or object
either takes a URI or a stream or some other object that only takes a
URI or a stream.

Why is everything a freaking stream? Almost all of the code I'm
upgrading passes around strings, which I have to turn around and
convert to streams to make work. Why couldn't MS add some overloads
that take string arguments as well?

Maybe I'm missing something obvious (wouldn't be the first time) but
having to convert all these strings to streams just seems asinine to
me.

End of rant.
 
camainc said:
I'm just now migrating to the 2.0 framework, and in working with the
System.Xml namespace, it seems like almost every method or object
either takes a URI or a stream or some other object that only takes a
URI or a stream.

Which methods are you referring to? I use System.Xml a lot (although
probably with a fairly specific set of functionality) and I don't recall
ever having to use a Stream in order to interact with it.
 
I was trying to figure out how to use the new XSLCompiledTransform()
class. It is not very intuitive at all.

The Transform method takes either a URI, an XMLReader or an
IXPathNavigable for the first argument, and an XMLWriter, a
IO.TextWriter or an IO.Stream for the second argument (if you skip the
"arguments" argument).

Why couldn't they have added an overload that would accept an
XMLDocument object and return a string? According to the docs, the
preferred first argument is an XPathNavigator object. To get the final
resulting string to write out to my web page, I had to write a
function like this (I found some clues in other news groups):

Public Function TransformXML(ByVal xmlString As String, ByVal
xsltPath As String) As String

Dim myXmlDoc As XmlDocument
Dim myXslt As Xsl.XslCompiledTransform
Dim mySW As IO.StringWriter
Dim myXTW As XmlTextWriter
Dim myResults As String = String.Empty

Try

myXmlDoc = New XmlDocument()
myXmlDoc.LoadXml(xmlString)

myXslt = New Xsl.XslCompiledTransform()
myXslt.Load(xsltPath)

mySW = New IO.StringWriter
myXTW = New XmlTextWriter(mySW)

myXslt.Transform(myXmlDoc.CreateNavigator(), myXTW)
myXTW.Flush()

myResults = mySW.ToString()

Finally
myXmlDoc = Nothing
myXslt = Nothing
mySW = Nothing
myXTW = Nothing
End Try

Return myResults

End Function

It just seems like an awful lot of work just to transform some XML.
 
Back
Top