|
|
|
| Non-WTF Job: IT Applications Manager at Questex Media Group (Auburndale, Ma) |
| « The Ear Michael and Danger! | The Really Big Log File » |
Although the .NET Framework ships with a comprehensive XML library, Sam B's coworkers aren't big fans of it. It's far too fancy, they claim. Instead, they prefer to use StringBuilders, concatenation, and IndexOf(">")-style parsing.
"What on Earth do we need XML-Navigation and Nodes for," they'll often rhetorically say, "come on, it's all just string manipulation!" As it turns out, "XML-Navigation" and "Nodes" certainly do come in handy, especially when one needs to, say, navigate nodes in XML, as they'll often have do.
Fortunately though, they've built an entire library of "XML string" manipulating functions that they use for this exact purpose. Following is ParseText(), one of many of their functions...
''' <summary>
''' Convert text to XML compatible text, so it can be appended
''' instead of using a dom to add a node.
''' </summary>
''' <param name="textIn"></param>
''' <returns>String</returns>
''' <remarks></remarks>
Public Shared Function ParseText(ByVal textIn As String) As String
Dim dom As XmlDocument = Nothing
Dim Node As XmlElement = Nothing
Dim Result As String
Try
dom = New XmlDocument
Node = dom.CreateElement("x")
Node.InnerText = textIn
Result = Node.OuterXml
If Result.Length() > 7 Then
Return Mid(Result, 4, Result.Length() - 7)
Else
Return ""
End If
Catch ex As Exception
Return ex.ToString
Finally
dom = Nothing
Node = Nothing
End Try
End Function
|
I agree with them, the .NET one is far too functional, so in our library we parse text by entering the string values into an efficient queue system where we email the incoming values to the most efficient available technie.. he gets given a parse session ticket that he logs back into our bespoke administration system and enters the validated/normalized result back to the system..
We find that the parsing does take a little longer than the .NET version, but it does allow us to normalize badly formed XML.. We've got patents on this so don't any of you cowboys even think about ripping us off! |
|
Wait I see the WTF
Should be
otherwise if an error occured, we wouldn't get xml back. |
Surely you mean
After all, if you've got a tool to clean up strings for XML, why not use it? |
|
My God. All they need to do is use frames! Problem solved!
|
Re: Far Too Fancy
2008-01-15 00:45
•
by
gagongsiraulo
(unregistered)
|
Wait! you forgot to place it inside CDATA section Return "<error>" +"<![CDATA[" + ex.ToString() + "]]>" + "</error>" so our error result is not malformed.. hmm.... how bout let's do String errorXml = "<error>" +"<![CDATA[" + ex.ToString() + "]]>" + "</error>" XmlDocument docError = new XmlDocument(); docError.LoadXml(errorXml); return docError.OuterXml There... we always get a well-formed xml.. good |
| « The Ear Michael and Danger! | The Really Big Log File » |