Regular expression to parse xml in .net
I have the following function that I am using to remove the characters \04 and nulls from my xmlString but I can't find what do I need to change to avoid removing the \ from my ending tags. This is what I get when I run this function
<ARR>20080625<ARR><DEP>20110606<DEP><PCIID>626783<PCIID><NOPAX>1<NOPAX><TG><TG><HASPREV>FALSE<HASPREV><HASSUCC>FALSE<HASSUCC>
Can anybody help me find out what do I need to change in my expression to keep the ending tag as </tag>
Private Function CleanInput(ByVal inputXML As String) As String
' Note - This will perform better if you compile the Regex and use a reference to it.
' That assumes it will still be memory-resident the next time it is invoked.
' Replace invalid characters with empty strings.
Return Regex.Replace(inputXML, "开发者_如何学Go[^><\w\.@-]", "")
End Function
Private Function CleanInput(ByVal inputXML As String) As String
Return Regex.Replace(inputXML, "[^/><\w\.@-]", "")
' --------------------------------^
End Function
But since your target is only removing the \04
and \00
's it's safer to restrict the replacement on them only.
Private Function CleanInput(ByVal inputXML As String) As String
Return Regex.Replace(inputXML, "[\4\0]", "")
End Function
精彩评论