比较并获得Xml差异

时间:2014-06-29 01:57:05

标签: xml vb.net git

在XML Change中进行somenthing时,我有两个XML的Get XML Diff代码 我的问题是如何配置输出以显示更改的节点名称?

例如,我得到了这个:

 <?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

0 个答案:

没有答案