在VB中替换xml文件的value属性中的双引号

在VB中替换xml文件的value属性中的双引号,xml,vb.net,import,replace,export,Xml,Vb.net,Import,Replace,Export,我的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"/> 或 Resu

我的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"/>


ResultString=Regex.Replace(SubjectString_
“(?[^”“]*”#匹配双引号,&chr(10)和_
“[^”“]*”“#可选非引号介于”&chr(10)和_
“*#任意次数。”&chr(10)和_
“[^”“]*#匹配任意数量的非引号”&chr(10)和_
“”#查找断言结束“&chr(10)&_
“#匹配一个引号”&chr(10)和_
(?!#断言以下内容在此处不匹配:&chr(10)&_
“\s+#空白”&chr(10)和_
“\w+=#类似value=“&chr(10)&_
“|#或”&chr(10)和_
“\s*#可选空白”&chr(10)和_
“[/?]?#后跟“或”或“无”&chr(10)和_
“>#后接>”&chr(10)和_
“#先行断言结束。”&chr(10)和_
“|#或在另一个方向上执行相同操作:&chr(10)&_
"(?[^""]*""[^""]*"")*[^""]*$)", _
“”,RegexOptions.IgnorePatternWhitespace)

您不能修复生成无效XML的程序吗?该程序不是我的。遗憾的是,我无法对其进行任何更改。您能否绝对确保该无效XML至少包含所有引号(即使是您希望替换的引号)正确平衡,并且任何属性中都没有
字符,任何地方都没有可能包含引号的注释或CDATA节?我可以验证,根本没有CDATA。整个xml的构建方式与上面相同,所有字段都有名称和值。
也是never在任何地方都使用过。它似乎几乎可以工作。xml的第一行也是经过编辑的
。其余的似乎都可以。@R.Schaaphuizen:好的,我将此案例添加到正则表达式中并对其进行了注释。?:谢谢,这是有效的。我已经更改了有关您的编辑的正则表达式,因此没有注释。它现在可以工作了:)
<field name="memo" value="24-06-2004 Lorem ipsum dolor 'sit' amit"/>
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)