正则表达式解析.net中的xml

Ton*_*ony 6 .net regex xml vb.net

我有以下的功能,我使用删除字符\ 04空值从我的xmlString,但我无法找到我需要做什么改变,以避免从我的结束标记去掉\.这是我运行此功能时得到的

<ARR>20080625<ARR><DEP>20110606<DEP><PCIID>626783<PCIID><NOPAX>1<NOPAX><TG><TG><HASPREV>FALSE<HASPREV><HASSUCC>FALSE<HASSUCC>
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我找出我需要在表达式中进行哪些更改以保留结束标记 </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, "[^><\w\.@-]", "")
End Function
Run Code Online (Sandbox Code Playgroud)

ken*_*ytm 4

Private Function CleanInput(ByVal inputXML As String) As String
    Return Regex.Replace(inputXML, "[^/><\w\.@-]", "")
    ' --------------------------------^
End Function
Run Code Online (Sandbox Code Playgroud)

但由于您的目标只是删除\04和 ,\00因此仅限制对它们的替换会更安全。

Private Function CleanInput(ByVal inputXML As String) As String
    Return Regex.Replace(inputXML, "[\4\0]", "")
End Function
Run Code Online (Sandbox Code Playgroud)