1

我的 xml 文件中有以下节点,它是另一个程序的导出。我必须在我的应用程序中编辑 xml 文件,以便以正确的方式导入它。

节点:

<field name="memo" value="24-06-2004 Lorem ipsum dolor "sit" amit"/>

最终它必须变成这样

<field name="memo" value="24-06-2004 Lorem ipsum dolor &quot;sit&quot; amit"/>

或者

<field name="memo" value="24-06-2004 Lorem ipsum dolor 'sit' amit"/>
4

1 回答 1

0
ResultString = Regex.Replace(SubjectString, _
    "(?<=         # Assert that this matches before the current position:" & chr(10) & _
    " ^           # Start of string                                      " & chr(10) & _
    " [^""]*""    # Match any number of non-quotes, then one quote       " & chr(10) & _
    " (?>[^""]*"" # Match pairs of quotes,                               " & chr(10) & _
    "    [^""]*"" # optional non-quotes in-between                       " & chr(10) & _
    " )*          # any number of times.                                 " & chr(10) & _
    " [^""]*      # Match any number of non-quotes                       " & chr(10) & _
    ")            # End of lookbehind assertion                          " & chr(10) & _
    """           # MATCH ONE QUOTE                                      " & chr(10) & _
    "(?!          # Assert that the following cannot match here:         " & chr(10) & _
    " \s+         #  Whitespace                                          " & chr(10) & _
    " \w+=        #  An identifier like value=                           " & chr(10) & _
    "|            # or                                                   " & chr(10) & _
    " \s*         #  optional whitespace                                 " & chr(10) & _
    " [/?]?       #  followed by either / or ? or nothing                " & chr(10) & _
    " >           #  followed by >                                       " & chr(10) & _
    ")            # End of lookahead assertion.                          " & chr(10) & _
    "|            # OR do the same in the other direction:               " & chr(10) & _
    "(?<!\w+=)""(?=[^""]*""(?>[^""]*""[^""]*"")*[^""]*$)", _
    "&quot;", RegexOptions.IgnorePatternWhitespace)
于 2013-02-14T09:42:45.890 回答