2009-11-19 14 views
11

क्या कोई ऐसे उपकरण के बारे में जानता है जो दो एक्सएमएल दस्तावेजों की तुलना करेगा। बेकार है कि मजाक कर रहा है ... और भी है। मुझे ऐसा कुछ चाहिए जो सुनिश्चित करेगा कि फ़ाइल 1 में प्रत्येक नोड ऑर्डर के बावजूद फ़ाइल 2 में भी है। मैंने सोचा कि एक्सएमएल जासूस इग्नोर ऑर्डर ऑफ चाइल्ड नोड्स विकल्प के साथ ऐसा करेगा लेकिन ऐसा नहीं हुआ। निम्नलिखित एक ही विचार किया जाएगा:बच्चे तत्वों के आदेश को अनदेखा कर एक्सएमएल की तुलना करें

<Node> 
    <Child name="Alpha"/> 
    <Child name="Beta"/> 
    <Child name="Charlie"/> 
</Node> 

<Node> 
    <Child name="Beta"/> 
    <Child name="Charlie"/> 
    <Child name="Alpha"/> 
</Node> 
+1

मैं वास्तव में क्या देख रहा हूँ। तो कौन सा तुलना उपकरण इस महत्वपूर्ण नवाचार को संभाल सकता है? – snahl

उत्तर

5

आप "XML diff tool" है, जो आप पर्याप्त परिणाम की तुलना में अधिक दे देंगे के लिए गूगल कर सकते हैं। उनमें से एक OxygenXml है, जो टूल मैं अक्सर उपयोग करता हूं। आप माइक्रोस्कोफ्ट XML Diff and Patch Tool भी कोशिश कर सकते हैं।

गुड लक।

+2

Google खोज ने मुझे आशा की थी कि कोई भी मुफ्त वादा निष्पादन योग्य डाउनलोड नहीं मिलेगा। हालांकि, एक्सएमएल डिफ और पैच टूल पर +1! यह आवश्यक है कि आपके पास .exe प्राप्त करने के लिए इसे बनाने के लिए विजुअल स्टूडियो है। एक अच्छा दृष्टि से स्वरूपित xml diff के लिए,/नमूने/XmlDiffView प्रोजेक्ट बनाएं, फिर XmlDiffView [-flags] 1.xml 2.xml visual-output.html – HaterTot

+0

चलाएं क्या ऑक्सीजनएक्सएमएल समर्थन ओपी अनुरोधों को दिखाता है? यह कैसे कॉन्फ़िगर किया गया है? –

+0

ऑक्सीजनएक्सएमएल विशेषता ऑर्डर को अनदेखा करता है, लेकिन ऐसा लगता है कि बाल तत्व ऑर्डर को अनदेखा नहीं कर रहा है ... – thisarattr

2

मैं इसके लिए XMLUnit का उपयोग करता हूं क्योंकि यह तत्वों को एक अलग क्रम में पूरा करने के लिए पूरा कर सकता है।

+0

मेरे पास इस दृष्टिकोण (XmlUnit 1 और 2 दोनों) के साथ सफलता की अलग-अलग डिग्री हैं। यह अक्सर काम करता है, लेकिन यह कभी-कभी विफल रहता है (एक्सएमएल के जोड़े के लिए जो आंखों को क्रमबद्ध क्रम के अलावा स्पष्ट रूप से समान हैं)। –

+0

यदि वे वास्तव में क्रमबद्ध क्रम के अलावा समान हैं जो ऐसा लगता है कि यह इसके साथ एक बग हो सकता है। यदि कोई मौजूदा समस्या है और इसकी रिपोर्ट कर रहा है तो आप इसकी जांच कर सकते हैं यदि आप इसे आसानी से पुन: उत्पन्न कर सकते हैं। –

1

मुझे इस शाम की समान आवश्यकता थी, और मेरी आवश्यकताओं के अनुरूप कुछ नहीं मिला।

मेरा कामकाज दो एक्सएमएल फाइलों को सॉर्ट करना था जिन्हें मैं अलग करना चाहता था, तत्व नाम से वर्णानुक्रम में क्रमबद्ध करना। एक बार जब वे एक सतत क्रम में थे, तो मैं एक नियमित दृश्य diff उपकरण का उपयोग कर दो क्रमबद्ध फ़ाइलों को अलग कर सकता था।

इस दृष्टिकोण किसी और के लिए उपयोगी लगता है, मैं अजगर स्क्रिप्ट मैं http://dalelane.co.uk/blog/?p=3225

0

एक (बहुत) त्वरित और गंदी दृष्टिकोण के रूप में छंटाई करने के लिए लिखा था साझा किया है, मैं एक चुटकी में यह कर दिया है : स्तंभ एक में

  1. ओपन एक्सेल
  2. पेस्ट फ़ाइल 1, प्रति पंक्ति एक लाइन। "FILE1" श्रेणी का नाम दें
  3. कॉलम बी में फ़ाइल 2 पेस्ट करें, प्रति पंक्ति एक पंक्ति। की तह तक

    =IF(ISERROR(VLOOKUP(A1,FILE2,1,FALSE)),"DIFF","") 
    
  4. कॉलम नीचे भरें सी और डी: नाम रेंज "करें 2"
  5. सी 1 में, पाठ बॉक्स सूत्र:

    =IF(ISERROR(VLOOKUP(B1,FILE1,1,FALSE)),"DIFF","") 
    
  6. डी 1 में, पाठ बॉक्स Forumula फ़ाइलें।

इससे किसी भी पंक्ति में दिखाई देने वाली किसी भी पंक्ति को हाइलाइट किया जाएगा, लेकिन दूसरी फ़ाइल नहीं। यह किसी भी खिंचाव से साफ नहीं है, लेकिन कभी-कभी आपको बस जो मिला है उसके साथ काम करना पड़ता है।

0

Beyond Compare के साथ आप File Formats-XML Sort सेटिंग में उपयोग कर सकते हैं। इस विकल्प के साथ एक्सएमएल बच्चों को diff से पहले हल किया जाएगा।

तुलना से परे का एक निशान/पोर्टेबल संस्करण available है।

0
/** 
    * @author sdiallo 
    * @since 2017-01-16 
    * <p> 
    * Compare the content of two XML file 
    * </p> 
    * <ul> 
    * <li>Ignore the white space</li> 
    * <li>Ignore the attribute order</li> 
    * <li>Ignore the comment</li> 
    * <li>Ignore Sequence child nodes are not the same</li> 
    * <ul> 
    * 
    * @param String XML 
    *   first Content to be compared 
    * @param String XML 
    *   second Content to be compared 
    * @return List the differences computed between the two files 
    *   <ul> 
    *   <li>null means the files are equal</li>   
    *   <li>elsewhere the files are different</li> 
    *   <ul> 
    * */ 
    public static List buildDiffXMLs(String xmlExpected, String xmlGenerated) { 
     List<?> differencesList = null; 

    XMLUnit.setIgnoreAttributeOrder(true); 
    XMLUnit.setIgnoreComments(true); 
    XMLUnit.setIgnoreWhitespace(true); 

    try { 
     DetailedDiff diff = new DetailedDiff(XMLUnit.compareXML(
       xmlExpected, xmlGenerated)); 

     // Two documents are considered to be "similar" if they contain the 
     // same elements and attributes regardless of order. 
     if (!diff.identical() && !diff.similar()) { 
      differencesList = diff.getAllDifferences(); 
     }// end if 

    } catch (SAXException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    return differencesList; 
}// buildDiffXMLs 
+1

संकेत: कृपया अपने कोड के ** ** ** को ठीक से प्रारूपित करने में 1 मिनट बिताए; और शायद वहां एक प्रारंभिक स्पष्टीकरण डाल दिया। – GhostCat

0

मैं हाल ही में एक ऐसी ही जवाब यहाँ (Open source command line tool for Linux to diff XML files ignoring element order) दे दी है, लेकिन मैं और अधिक विस्तार प्रदान करेंगे ...

यदि आप लिखना एक कार्यक्रम दो पेड़ों को एक साथ चलने के लिए, आप के लिए तर्क अनुकूलित कर सकते हैं पेड़ों के बीच "मैचों" की पहचान करना, और उन नोड्स को संभालने के लिए भी जो मेल नहीं खाते हैं। xslt 2 में एक उदाहरण है।0 (खेद यह बहुत देर है):

<xsl:stylesheet version="2.0" 
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
       xmlns:xs="http://www.w3.org/2001/XMLSchema" 

       xmlns:set="http://exslt.org/sets" 

       xmlns:primary="primary" 
       xmlns:control="control" 

       xmlns:util="util" 

       exclude-result-prefixes="xsl xs set primary control"> 

    <!-- xml diff tool 

     import this stylesheet from another and call the "compare" template with two args: 

      primary: the root of the primary tree to submit to comparison 
      control: the root of the control tree to compare against 

     the two trees will be walked together. the primary tree will be walked in document order, matching elements 
     and attributes from the control tree along the way, building a tree of common content, with appendages 
     containing primary and control only content. that tree will then be used to generate the diff. 

     the process of matching involves finding, for an element or attribute in the primary tree, the 
     equivalent element or attribute in the control tree, *at the same level*, and *regardless of ordering*. 

      matching logic is encoded as templates with mode="find-match", providing a hook to wire in specific 
      matching logic for particular elements or attributes. for example, an element may "match" based on an 
      @id attribute value, irrespective of element ordering; encode this in a mode="find-match" template. 

      the treatment of diffs is encoded as templates with mode="primary-only" and "control-only", providing 
      hooks for alternate behavior upon encountering differences. 

      --> 

    <xsl:output method="text"/> 

    <xsl:strip-space elements="*"/> 

    <xsl:param name="full" select="false()"/><!-- whether to render the full doc, as opposed to just diffs --> 

    <xsl:template match="/"> 
     <xsl:call-template name="compare"> 
      <xsl:with-param name="primary" select="*/*[1]"/><!-- first child of root element, for example --> 
      <xsl:with-param name="control" select="*/*[2]"/><!-- second child of root element, for example --> 
     </xsl:call-template> 
    </xsl:template> 

    <!-- OVERRIDES: templates that can be overridden to provide targeted matching logic and diff treatment --> 

    <!-- default find-match template for elements 
     (by default, for "complex" elements, name has to match, for "simple" elements, name and value do) 
     for context node (from "primary"), choose from among $candidates (from "control") which one matches 
     (override with more specific match patterns to effect alternate behavior for targeted elements) 
     --> 
    <xsl:template match="*" mode="find-match" as="element()?"> 
     <xsl:param name="candidates" as="element()*"/> 
     <xsl:choose> 
      <xsl:when test="text() and count(node()) = 1"><!-- simple content --> 
       <xsl:sequence select="$candidates[node-name(.) = node-name(current())][text() and count(node()) = 1][. = current()][1]"/> 
      </xsl:when> 
      <xsl:when test="not(node())"><!-- empty --> 
       <xsl:sequence select="$candidates[node-name(.) = node-name(current())][not(node())][1]"/> 
      </xsl:when> 
      <xsl:otherwise><!-- presumably complex content --> 
       <xsl:sequence select="$candidates[node-name(.) = node-name(current())][1]"/> 
      </xsl:otherwise> 
     </xsl:choose> 
    </xsl:template> 

    <!-- default find-match template for attributes 
     (by default, name and value have to match) 
     for context attr (from "primary"), choose from among $candidates (from "control") which one matches 
     (override with more specific match patterns to effect alternate behavior for targeted attributes) 
     --> 
    <xsl:template match="@*" mode="find-match" as="attribute()?"> 
     <xsl:param name="candidates" as="attribute()*"/> 
     <xsl:sequence select="$candidates[. = current()][node-name(.) = node-name(current())][1]"/> 
    </xsl:template> 

    <!-- default primary-only template (override with more specific match patterns to effect alternate behavior) --> 
    <xsl:template match="@* | *" mode="primary-only"> 
     <xsl:apply-templates select="." mode="illegal-primary-only"/> 
    </xsl:template> 

    <!-- write out a primary-only diff --> 
    <xsl:template match="@* | *" mode="illegal-primary-only"> 
     <primary:only> 
      <xsl:copy-of select="."/> 
     </primary:only> 
    </xsl:template> 

    <!-- default control-only template (override with more specific match patterns to effect alternate behavior) --> 
    <xsl:template match="@* | *" mode="control-only"> 
     <xsl:apply-templates select="." mode="illegal-control-only"/> 
    </xsl:template> 

    <!-- write out a control-only diff --> 
    <xsl:template match="@* | *" mode="illegal-control-only"> 
     <control:only> 
      <xsl:copy-of select="."/> 
     </control:only> 
    </xsl:template> 

    <!-- end OVERRIDES --> 

    <!-- MACHINERY: for walking the primary and control trees together, finding matches and recursing --> 

    <!-- compare "primary" and "control" trees (this is the root of comparison, so CALL THIS ONE !) --> 
    <xsl:template name="compare"> 
     <xsl:param name="primary"/> 
     <xsl:param name="control"/> 

     <!-- write the xml diff into a variable --> 
     <xsl:variable name="diff"> 
      <xsl:call-template name="match-children"> 
       <xsl:with-param name="primary" select="$primary"/> 
       <xsl:with-param name="control" select="$control"/> 
      </xsl:call-template> 
     </xsl:variable> 

     <!-- "print" the xml diff as textual output --> 
     <xsl:apply-templates select="$diff" mode="print"> 
      <xsl:with-param name="render" select="$full"/> 
     </xsl:apply-templates> 

    </xsl:template> 

    <!-- assume primary (context) element and control element match, so render the "common" element and recurse --> 
    <xsl:template match="*" mode="common"> 
     <xsl:param name="control"/> 

     <xsl:copy> 
      <xsl:call-template name="match-attributes"> 
       <xsl:with-param name="primary" select="@*"/> 
       <xsl:with-param name="control" select="$control/@*"/> 
      </xsl:call-template> 

      <xsl:choose> 
       <xsl:when test="text() and count(node()) = 1"> 
        <xsl:value-of select="."/> 
       </xsl:when> 
       <xsl:otherwise> 
        <xsl:call-template name="match-children"> 
         <xsl:with-param name="primary" select="*"/> 
         <xsl:with-param name="control" select="$control/*"/> 
        </xsl:call-template> 
       </xsl:otherwise> 
      </xsl:choose> 
     </xsl:copy> 

    </xsl:template> 

    <!-- find matches between collections of attributes in primary vs control --> 
    <xsl:template name="match-attributes"> 
     <xsl:param name="primary" as="attribute()*"/> 
     <xsl:param name="control" as="attribute()*"/> 
     <xsl:param name="primaryCollecting" as="attribute()*"/> 

     <xsl:choose> 
      <xsl:when test="$primary and $control"> 
       <xsl:variable name="this" select="$primary[1]"/> 
       <xsl:variable name="match" as="attribute()?"> 
        <xsl:apply-templates select="$this" mode="find-match"> 
         <xsl:with-param name="candidates" select="$control"/> 
        </xsl:apply-templates> 
       </xsl:variable> 

       <xsl:choose> 
        <xsl:when test="$match"> 
         <xsl:copy-of select="$this"/> 
         <xsl:call-template name="match-attributes"> 
          <xsl:with-param name="primary" select="subsequence($primary, 2)"/> 
          <xsl:with-param name="control" select="remove($control, 1 + count(set:leading($control, $match)))"/> 
          <xsl:with-param name="primaryCollecting" select="$primaryCollecting"/> 
         </xsl:call-template> 
        </xsl:when> 
        <xsl:otherwise> 
         <xsl:call-template name="match-attributes"> 
          <xsl:with-param name="primary" select="subsequence($primary, 2)"/> 
          <xsl:with-param name="control" select="$control"/> 
          <xsl:with-param name="primaryCollecting" select="$primaryCollecting | $this"/> 
         </xsl:call-template> 
        </xsl:otherwise> 
       </xsl:choose> 

      </xsl:when> 
      <xsl:otherwise> 
       <xsl:if test="$primaryCollecting | $primary"> 
        <xsl:apply-templates select="$primaryCollecting | $primary" mode="primary-only"/> 
       </xsl:if> 
       <xsl:if test="$control"> 
        <xsl:apply-templates select="$control" mode="control-only"/> 
       </xsl:if> 
      </xsl:otherwise> 
     </xsl:choose> 

    </xsl:template> 

    <!-- find matches between collections of elements in primary vs control --> 
    <xsl:template name="match-children"> 
     <xsl:param name="primary" as="node()*"/> 
     <xsl:param name="control" as="element()*"/> 

     <xsl:variable name="this" select="$primary[1]" as="node()?"/> 

     <xsl:choose> 
      <xsl:when test="$primary and $control"> 
       <xsl:variable name="match" as="element()?"> 
        <xsl:apply-templates select="$this" mode="find-match"> 
         <xsl:with-param name="candidates" select="$control"/> 
        </xsl:apply-templates> 
       </xsl:variable> 

       <xsl:choose> 
        <xsl:when test="$match"> 
         <xsl:apply-templates select="$this" mode="common"> 
          <xsl:with-param name="control" select="$match"/> 
         </xsl:apply-templates> 
        </xsl:when> 
        <xsl:otherwise> 
         <xsl:apply-templates select="$this" mode="primary-only"/> 
        </xsl:otherwise> 
       </xsl:choose> 
       <xsl:call-template name="match-children"> 
        <xsl:with-param name="primary" select="subsequence($primary, 2)"/> 
        <xsl:with-param name="control" select="if (not($match)) then $control else remove($control, 1 + count(set:leading($control, $match)))"/> 
       </xsl:call-template> 
      </xsl:when> 
      <xsl:when test="$primary"> 
       <xsl:apply-templates select="$primary" mode="primary-only"/> 
      </xsl:when> 
      <xsl:when test="$control"> 
       <xsl:apply-templates select="$control" mode="control-only"/> 
      </xsl:when> 
     </xsl:choose> 

    </xsl:template> 

    <!-- end MACHINERY --> 

    <!-- PRINTERS: print templates for writing out the diff --> 

    <xsl:template match="*" mode="print"> 
     <xsl:param name="depth" select="-1"/> 
     <xsl:param name="render" select="false()"/> 
     <xsl:param name="lineLeader" select="' '"/> 
     <xsl:param name="rest" as="element()*"/> 

     <xsl:if test="$render or descendant::primary:* or descendant::control:*"> 

      <xsl:call-template name="whitespace"> 
       <xsl:with-param name="indent" select="$depth"/> 
       <xsl:with-param name="leadChar" select="$lineLeader"/> 
      </xsl:call-template> 
      <xsl:text>&lt;</xsl:text> 
      <xsl:value-of select="name(.)"/> 

      <xsl:apply-templates select="@* | primary:*[@*] | control:*[@*]" mode="print"> 
       <xsl:with-param name="depth" select="$depth"/> 
       <xsl:with-param name="render" select="$render"/> 
       <xsl:with-param name="lineLeader" select="$lineLeader"/> 
      </xsl:apply-templates> 

      <xsl:choose> 
       <xsl:when test="text() and count(node()) = 1"><!-- field element (just textual content) --> 
        <xsl:text>&gt;</xsl:text> 
        <xsl:value-of select="."/> 
        <xsl:text>&lt;/</xsl:text> 
        <xsl:value-of select="name(.)"/> 
        <xsl:text>&gt;</xsl:text> 
       </xsl:when> 
       <xsl:when test="count(node()) = 0"><!-- empty (self-closing) element --> 
        <xsl:text>/&gt;</xsl:text> 
       </xsl:when> 
       <xsl:otherwise><!-- complex content --> 
        <xsl:text>&gt;&#10;</xsl:text> 
        <xsl:apply-templates select="*[not(self::primary:* and @*) and not(self::control:* and @*)]" mode="print"> 
         <xsl:with-param name="depth" select="$depth + 1"/> 
         <xsl:with-param name="render" select="$render"/> 
         <xsl:with-param name="lineLeader" select="$lineLeader"/> 
        </xsl:apply-templates> 
        <xsl:call-template name="whitespace"> 
         <xsl:with-param name="indent" select="$depth"/> 
         <xsl:with-param name="leadChar" select="$lineLeader"/> 
        </xsl:call-template> 
        <xsl:text>&lt;/</xsl:text> 
        <xsl:value-of select="name(.)"/> 
        <xsl:text>&gt;</xsl:text> 
       </xsl:otherwise> 
      </xsl:choose> 

      <xsl:text>&#10;</xsl:text> 

     </xsl:if> 

     <!-- write the rest of the elements, if any --> 
     <xsl:apply-templates select="$rest" mode="print"> 
      <xsl:with-param name="depth" select="$depth"/> 
      <xsl:with-param name="render" select="$render"/> 
      <xsl:with-param name="lineLeader" select="$lineLeader"/> 
      <xsl:with-param name="rest" select="()"/><!-- avoid implicit param pass to recursive call! --> 
     </xsl:apply-templates> 

    </xsl:template> 

    <xsl:template match="@*" mode="print"> 
     <xsl:param name="depth" select="0"/> 
     <xsl:param name="render" select="false()"/> 
     <xsl:param name="lineLeader" select="' '"/> 
     <xsl:param name="rest" as="attribute()*"/> 

     <xsl:if test="$render"> 

      <xsl:text>&#10;</xsl:text> 
      <xsl:call-template name="whitespace"> 
       <xsl:with-param name="indent" select="$depth + 3"/> 
       <xsl:with-param name="leadChar" select="$lineLeader"/> 
      </xsl:call-template> 
      <xsl:value-of select="name(.)"/> 
      <xsl:text>="</xsl:text> 
      <xsl:value-of select="."/> 
      <xsl:text>"</xsl:text> 
     </xsl:if> 

     <xsl:apply-templates select="$rest" mode="print"> 
      <xsl:with-param name="depth" select="$depth"/> 
      <xsl:with-param name="render" select="$render"/> 
      <xsl:with-param name="lineLeader" select="$lineLeader"/> 
      <xsl:with-param name="rest" select="()"/><!-- avoid implicit param pass to recursive call! --> 
     </xsl:apply-templates> 

    </xsl:template> 

    <xsl:template match="primary:* | control:*" mode="print"> 
     <xsl:param name="depth"/> 

     <xsl:variable name="diffType" select="util:diff-type(.)"/> 
     <xsl:variable name="primary" select="self::primary:*"/> 
     <xsl:variable name="lineLeader" select="if ($primary) then '+' else '-'"/> 

     <!-- only if this is the first in a sequence of control::* elements, since the rest are handled along with the first... --> 
     <xsl:if test="util:diff-type(preceding-sibling::*[1]) != $diffType"> 
      <xsl:if test="@*"> 
       <xsl:text>&#10;</xsl:text> 
      </xsl:if> 
      <xsl:call-template name="diffspace"> 
       <xsl:with-param name="indent" select="if (@*) then $depth + 3 else $depth"/> 
       <xsl:with-param name="primary" select="$primary"/> 
      </xsl:call-template> 
      <b><i>&lt;!-- ... --&gt;</i></b><!-- something to identify diff sections in output --> 
      <xsl:if test="node()"> 
       <xsl:text>&#10;</xsl:text> 
      </xsl:if> 
      <xsl:variable name="rest" select="set:leading(following-sibling::*, following-sibling::*[util:diff-type(.) != $diffType])"/> 
      <xsl:apply-templates select="@* | node()" mode="print"> 
       <xsl:with-param name="depth" select="$depth"/> 
       <xsl:with-param name="render" select="true()"/> 
       <xsl:with-param name="lineLeader" select="$lineLeader"/> 
       <xsl:with-param name="rest" select="$rest/@* | $rest/*"/> 
      </xsl:apply-templates> 
     </xsl:if> 
    </xsl:template> 

    <xsl:template name="whitespace"> 
     <xsl:param name="indent" select="0" as="xs:integer"/> 
     <xsl:param name="leadChar" select="' '"/> 
     <xsl:choose> 
      <xsl:when test="$indent > 0"> 
       <xsl:value-of select="$leadChar"/> 
       <xsl:text> </xsl:text> 
       <xsl:for-each select="0 to $indent - 1"> 
        <xsl:text> </xsl:text> 
       </xsl:for-each> 
      </xsl:when> 
      <xsl:otherwise> 
       <xsl:for-each select="0 to $indent"> 
        <xsl:text> </xsl:text> 
       </xsl:for-each> 
      </xsl:otherwise> 
     </xsl:choose> 
    </xsl:template> 

    <xsl:template name="diffspace"> 
     <xsl:param name="indent" select="0" as="xs:integer"/> 
     <xsl:param name="primary" select="false()"/> 
     <xsl:for-each select="0 to $indent"> 
      <xsl:choose> 
       <xsl:when test="$primary"> 
        <xsl:text>++</xsl:text> 
       </xsl:when> 
       <xsl:otherwise> 
        <xsl:text>--</xsl:text> 
       </xsl:otherwise> 
      </xsl:choose> 
     </xsl:for-each> 
    </xsl:template> 

    <!-- just an "enum" for deciding whether to group adjacent diffs --> 
    <xsl:function name="util:diff-type" as="xs:integer"> 
     <xsl:param name="construct"/> 
     <xsl:sequence select="if ($construct/self::primary:*[@*]) then 1 else 
           if ($construct/self::control:*[@*]) then 2 else 
           if ($construct/self::primary:*) then 3 else 
           if ($construct/self::control:*) then 4 else 
           if ($construct) then 5 else 0"/> 
    </xsl:function> 

    <!-- end PRINTERS --> 

</xsl:stylesheet> 

, इस उदाहरण इनपुट पर विचार तुम्हारा पर आधारित स्टाइलशीट साथ

<test> 
    <Node> 
     <Child name="Alpha"/> 
     <Child name="Beta"/> 
     <Child name="Charlie"/> 
    </Node> 
    <Node> 
     <Child name="Beta"/> 
     <Child name="Charlie"/> 
     <Child name="Alpha"/> 
    </Node> 
</test> 

है के रूप में है, तो निम्न उत्पादन जब उदाहरण के लिए आवेदन किया है:

<Node> 
    <Child 
++++++++<!-- ... --> 
+  name="Alpha" 
--------<!-- ... --> 
-  name="Beta"> 
    </Child> 
    <Child 
++++++++<!-- ... --> 
+  name="Beta" 
--------<!-- ... --> 
-  name="Charlie"> 
    </Child> 
    <Child 
++++++++<!-- ... --> 
+  name="Charlie" 
--------<!-- ... --> 
-  name="Alpha"> 
    </Child> 
</Node> 

लेकिन आप इस कस्टम टेम्पलेट जोड़ने:

<xsl:template match="Child" mode="find-match" as="element()?"> 
    <xsl:param name="candidates" as="element()*"/> 
    <xsl:sequence select="$candidates[@name = current()/@name][1]"/> 
</xsl:template> 

जो @name विशेषता के आधार पर Child तत्व से मेल खाता है, तो आपको कोई आउटपुट नहीं मिलता है (जिसका अर्थ है कि कोई अंतर नहीं है)।

4

मैं इस के लिए एक सरल अजगर उपकरण xmldiffs बुलाया लिखा है:

तत्व अनदेखी दो एक्सएमएल फाइल की तुलना करें, और आदेश विशेषता।

उपयोग: xmldiffs [OPTION] FILE1 FILE2

किसी भी अतिरिक्त विकल्प diff आदेश को पारित कर रहे हैं।

https://github.com/joh/xmldiffs

0

यहाँ पर यह जाओ SWI-Prolog का उपयोग कर एक diff समाधान है

:- use_module(library(xpath)). 
load_trees(XmlRoot1, XmlRoot2) :- 
    load_xml('./xml_source_1.xml', XmlRoot1, _), 
    load_xml('./xml_source_2.xml', XmlRoot2, _). 

find_differences(Reference, Root1, Root2) :- 
    xpath(Root1, //'Child'(@name=Name), Node), 
    not(xpath(Root2, //'Child'(@name=Name), Node)), 
    writeln([Reference, Name, Node]). 

diff :- 
    load_trees(Root1, Root2), 
    (find_differences('1', Root1, Root2) ; find_differences('2', Root2, Root1)). 

Prolog नाम चर पर फ़ाइल 1 से नोड्स से मेल खाते हैं और फाइल करने के लिए 2. एकीकरण को एकजुट करेंगे नोड वैरिएबल "diff" पहचान करता है।

यहाँ नीचे कुछ नमूना उत्पादन है:

% file 1 and file 2 have no differences 
?- diff. 
false. 

% "Alpha" was updated in file 2 
?- diff. 
[1,Alpha,element(Child,[name=Alpha],[])] 
[2,Alpha,element(Child,[name=Alpha,age=7],[])] 
false. 
संबंधित मुद्दे