例如,我得到了这个:
<?xml version="1.0" encoding="utf-16"?>
<xd:xmldiff version="1.0" srcDocHash="14065382161691288455" options="IgnoreChildOrder IgnoreNamespaces IgnorePrefixes " fragments="no" xmlns:xd="http://schemas.microsoft.com/xmltools/2002/xmldiff">
<xd:node match="1">
<xd:node match="2">
<xd:node match="1">
<xd:change match="1">ADFGFFDFD</xd:change>
</xd:node>
</xd:node>
</xd:node>
</xd:xmldiff>
我想要这个:
<?xml version="1.0" encoding="utf-16"?>
<xd:xmldiff version="1.0" srcDocHash="14065382161691288455" options="IgnoreChildOrder IgnoreNamespaces IgnorePrefixes " fragments="no" xmlns:xd="http://schemas.microsoft.com/xmltools/2002/xmldiff">
<xd:node match="1">
<xd:node match="2">
<xd:node match="1">
<xd:change match="1"><NAME>ADFGFFDFDM<NAME></xd:change>
</xd:node>
</xd:node>
</xd:node>
</xd:xmldiff>
Vb.net代码:
Public Function GenDiff(Nodea As String, Nodeb As String, ByRef difDoc As String) As Boolean
Dim xmldiff As New XmlDiff()
xmldiff.IgnoreChildOrder = True
xmldiff.IgnoreNamespaces = True
xmldiff.IgnorePrefixes = True
xmldiff.IgnoreComments = False
xmldiff.IgnorePI = False
xmldiff.IgnoreWhitespace = False
xmldiff.Algorithm = XmlDiffAlgorithm.Auto
Dim StreamW As New StringWriter()
Dim XmlWriter As New XmlTextWriter(StreamW)
XmlWriter.Formatting = Formatting.Indented
Dim Oreader As New XmlTextReader(New StringReader(Nodea))
Dim Mreader As New XmlTextReader(New StringReader(Nodeb))
Dim status As Boolean = xmldiff.Compare(Oreader, Mreader, XmlWriter)
difDoc = StreamW.ToString()
XmlWriter.Close()
Oreader.Close()
Mreader.Close()
Return status
End Function