XML Comparison

Hi,
I want to compare 2 xml files and identify the difference in the values between the tags and log it across in a table. I am new to this xml stuff in pl/sql.Can someone please help me with letting me know how to compare 2 xml files in Oracle using pl/sql code.
Thanks,
Vijay

without knowing your db version, I'd say use xmldiff() which is available in 11g.

Similar Messages

  • XML Comparison without DTD & XSD and able to return XPath of the Diff Node

    Dear All,
    I am new xml concept in java.
    First xml can have n of nodes and second xml can have n of the node.
    The node is new to second xml when compare to first xml.It has to go change list.
    1. My job is to compare 2 xml document and return the XPath of the Nodes.
    2. Both xml do not have any association like XSD,DTD and XSLT.
    3. I am looking for java api to find/return xpath of the node.
    Please help me.
    Saravanan.P

    Don't know if there's a method for this in the default XML parsing interface of Java (JAXP). I never came across a method which would return an XPath expression based on a Node and a Document. Only the other way around: return the Node(s) based on a Document and an XPath expression. Maybe some Java XML framework like XStream or an Apache XML framework have this functionality. It would be possible (not really nice though) to create such a method yourself. Based on a Document and a Node as input you could iterate through the parent elements until you reach the root Node and return the path. You would need to take into account that a Node can be part of a NodeList, so you have to retrieve the index of the Node in the list too.
    Ronald

  • XML - comparison of to files

    Hi,
    I have 2 XML files with the same structure.
    How do I compare it?
    I found one on internet, http://www.deltaxml.com/core/
    but it cost a lot.
    - Any free API ?
    - Any idea, any URL, special keyword to search for?
    -Aykut

    No, your requirement is totally unclear. Comparing two text files for differences is not at all easy -- suppose you only move a line to a different part of the file, how should that be reported? And comparing a tree structure adds another level of complexity.
    If you start writing down pairs of XML documents that differ slightly, trying to make things as difficult as possible for yourself, you should be able to see how complex the task actually is.
    Now, I am sure somebody has written an XML diff program that does sort of what you would want it to do. But since it's such a complex task, I don't find it surprising that they want money for the program.
    I searched for "xml diff" and found several programs and articles.

  • XML Object Comparison

    When comparing two XML objects, it appears that flexunit is reporting their equality when the values of XML elements are not equal.
    Here's a valid example:
    var xmlA:XML =
    <root>
         <element1>text1</element1>
         <element2>text2</element2>
    </root>;
    var xmlB:XML =
    <root>
         <element2>text2</element2>
         <element1>text1</element1>
    </root>;
    Assert.assertTrue(ObjectUtil.compare(xmlA, xmlB) == 0)   => true
    This is correct: element order does not matter and $xmlA/root/element1 == $xmlB/root/element1
    Here's an invalid example:
    var xmlA:XML =
    <root>
         <element1>text1</element1>
         <element2>text2</element2>
    </root>;
    var xmlB:XML =
    <root>
         <element1>text3</element1>
         <element2>text2</element2>
    </root>;
    Assert.assertTrue(ObjectUtil.compare(xmlA, xmlB) == 0)   => true
    This is NOT correct: $xmlA/root/element1 != $xmlB/root/element1
    Can somebody confirm this?  If confirmed, is this by design or am I missing something?
    Thanks!
    Sam

    As you've discovered, the problem is with your comparison. XML in Actionscript are really objects under the hood.
    Lets say you had this:
    var xml1:Object = {element1: "text1", element2: "text2"};
    var xml2:Object = {element2: "text2", element1: "text1"};
    Here, just like you want to do the XML comparison, the order of the properties doesn't matter, but you want to check the values of a particular property.
    So xml1 == xml2 fails not because the element values are out of order, but because the comparison occurs on the objects themselves, and not the properties in the objects.
    In order for my object comparison to succeed, I would probably need to create a hash of properties from both objects and verify that the keys are the same and the values of matching keys are the same if I don't want to use any of the built in utilities for comparing objects.
    So, in your example, the comparison you want to use is E4X, doing something like this:
    Assert.assertTrue( xmlA.element1.text()[0], xmlB.element1.text()[0]);
    I'm not sure how to write an E4X expression traversing two nodes at once, but maybe that will give you some ideas to go on?

  • How to remove indents from XML?

    I have a xml like this:
    <?xml version="1.0" encoding="UTF-8"?>
    <view>
         <help>
              <block>No.1</block>
              <device>USB</device>
         </help>     
    </view>
    How could I output the xml to :
    <?xml version="1.0" encoding="UTF-8"?><view><help><block>No.1</block>          <device>USB</device></help></view>
    The reason to output like this is to make the xml comparison passed.
    I use org.custommonkey.xmlunit.XMLTestCase.compareXML to compare two xml string, one from Java code, the other from C# code. Now, since there are new lines and whitespaces embedded in the Java generated XML, the comparison always failed. Is there any way to output the indent xml to the one string only?

    Try running the strings through something like this before comparing:
    String <stringname> = <stringname>.replaceAll("\\n|\\t|\\s|\\r", "");
    that should normalize them both to no spaces, tabs, newlines, carrage returns.

  • XML diff - ignoring order

    I'm working a project which basically involves producing a diff of 2 XML files. I recently discovered XDK and though that this would be the best way to do this.
    However, after I implemented the XDK solution, I found that it makes a distinction between files with different node ordering, even when these are logically equivalent. The files I am operating on have no ordering guarantees. Is there a way to accomplish a logical (rather than physical) XML comparison using XKD? Or should I look at another product?

    How are you processing the XML? Are you passing XML directly to merge or are you using XML Agent to transform the data to field nominated? Are you applying an XSLT?

  • Tree selection bug?

    Hi,
    I don't know if this is a bug or not. When using XML as the
    data provider for the Tree component and multiple nodes have the
    same label, selecting anyone of the nodes will cause all of them to
    be selected. The problem stems from the fact that XML comparison is
    done by value. The comparison is dibe at line 6345 of ListBase. Is
    this a bug? If not, is there a known workaround?
    I attached code that reproduces the problem. Selecting the
    first node, selects the first, second and last node because, by
    value, they are all the same.
    Thanks!
    JPB

    Switch to using a strongly typed object that implements IUID,
    or just make
    sure your XML has other identifying information to it. It's
    not really that
    helpful to have 19 "foos" in your list unless there is
    something else
    different about them.
    So, something like
    <mx:XMLList id="treeData">
    <node label="Test entry 1" id="1"/>
    <node label="Test entry 1" id="2"/>
    <node label="Test entry 2" id="3"/>
    <node label="Test entry 1" id="4"/>
    </mx:XMLList>
    HTH;
    Amy
    "jpbouchard" <[email protected]> wrote in
    message
    news:g941f3$1u8$[email protected]..
    > Hi,
    >
    > I don't know if this is a bug or not. When using XML as
    the data provider
    > for
    > the Tree component and multiple nodes have the same
    label, selecting
    > anyone of
    > the nodes will cause all of them to be selected. The
    problem stems from
    > the
    > fact that XML comparison is done by value. The
    comparison is dibe at line
    > 6345
    > of ListBase. Is this a bug? If not, is there a known
    workaround?
    >
    > I attached code that reproduces the problem. Selecting
    the first node,
    > selects
    > the first, second and last node because, by value, they
    are all the same.
    >
    > Thanks!
    > JPB
    >
    > <?xml version="1.0" encoding="utf-8"?>
    > <mx:VBox xmlns:mx="
    http://www.adobe.com/2006/mxml"
    width="100%"
    > height="100%">
    > <mx:Script>
    > <![CDATA[
    > import mx.controls.Tree;
    >
    > private function selectFirst(): void {
    > myTree.selectedItem = treeData[0];
    > }
    >
    > ]]>
    > </mx:Script>
    >
    > <mx:XMLList id="treeData">
    > <node label="Test entry 1"/>
    > <node label="Test entry 1"/>
    > <node label="Test entry 2"/>
    > <node label="Test entry 1"/>
    > </mx:XMLList>
    >
    > <mx:Panel title="Tree Selection Bug" height="100%"
    width="100%"
    > paddingTop="10" paddingLeft="10" paddingRight="10"
    paddingBottom="10">
    > <mx:Button label="Select First"
    click="selectFirst()"/>
    > <mx:Tree id="myTree" width="100%" height="100%"
    labelField="@label"
    > showRoot="true" dataProvider="{treeData}"/>
    > </mx:Panel>
    >
    > </mx:VBox>
    >

  • SQL to find out changes

    Hi,
    I have a table with 50 columns, lets call it Table_A . There is a identical table called Table_B. The data in Table_B gets flushed every night and data from Table_A is moved to Table_B. A new set of data is inserted into Table_A. Now I need to find out which field value is changed and what is changed . A minus command can give the changed records, but how to get the what was prior value for each changed field . Here is what I am looking for
    WITH TABLE_A AS  (  SELECT 1 ID, 'JOHN' NAME,  'SALES' DIV FROM DUAL
    UNION
            SELECT 2 ID, 'MARRY' NAME,  'ACCOUNTS' DIV FROM DUAL
    UNION
            SELECT 3 ID, 'KIM' NAME,  'SERVICE' DIV FROM DUAL),
    TABLE_B AS  (  SELECT 1 ID, 'JOHN' NAME,  'SALES' DIV FROM DUAL
    UNION
            SELECT 2 ID, 'MARRY' NAME,  'ACCOUNTS' DIV FROM DUAL
    UNION
            SELECT 3 ID, 'KIM' NAME,  'SALES' DIV FROM DUAL) 
    SELECT * FROM TABLE_A
    MINUS
    SELECT * FROM TABLE_B
    what i want is something that will spit out this (only one record, because there is only one diff record found in the above query.)
    ID,     OLD_ID,     NAME,   OLD_NAME ,  DIV ,       OLD_DIV
    3           3       KIM       KIM       SERVICE     SALESThe above one is for sample purpose, The actual table has 50 fields, and except the ID field, all other field values might change.
    All ideas and solutions are appreciated.
    Thanks in advance.

    >
    I understand your frustration. Here is the scenario. There are set of 5 tables. 1 master and 4 child tables ( and an identical set of 5 tables called "prior" tables, to store the flushed data from the "current" 5 tables). Every night data comes in XML files, the data from the 5 "prior" tables get flushed out . The data from the 5"current" table set moves to 5 "prior" tables. Then XML data gets loaded into the 5 "current"tables. Now once XML gets loaded into the original table ,I have to find out the diffs in those 5 tables(between current and prior) and generate result sets listing only the columns that have changed value. So what is current value and what was the prior value(from the prior table) side by side .
    >
    I'm not frustrated. It's just that any suggestions we make are solely based on the information provided. Sometimes posters start focusing on the solution they want to use (which is ok for their viewpoint) and don't explain the actual problem they are trying to solve. That often limits our ability to understand the options.
    Now that you posted the above there is another option you could use that might better deal with some of the issues people have mentioned.
    That solution is to compare the XML versions of the data. You haven't mentioned HOW you load that XML data into relational tables (what tool and process) but there is one VERY USEFUL feature of data in XML format:
    ALL data is already in TEXT format (excluding the obvious LOB possibilities, which you also haven't mentioned).
    That means ALL datatypes can use simple string comparison to detect differences: numbers, dates, character data. The actual meaning doesn't matter. If even a single byte is different the value can be considered different.
    Oracle uses XML and XSLT functionality as the base for their DBMS_METADATA_DIFF package. That package is used to compare schemas or databases to detect object (e.g. tables, views) differences and to automatically produce DDL for ALTER statements that can modify an object to have the same structure as the objects being compared.
    I suggest that you consider doing your comparisons on the XML versions of the data. Each night you would compare the new XML file data against the previous night's XML data. You can use XSLT to do the comparison and also to produce an XML file that contains the differences. Then you can use that 'difference' file as the source of your process to ultimately display the data.
    An additional advantage of doing the XML comparisons is that you can do them asynchronously as soon as the new file is available. And the, if you don't really need the 'change' info in the database you never need to load it. Just transform the change XML into an Excel file or flat file format for users to load into Excel for review.
    Do you license the partitioning option? If so then another suggestion would be to stop doing your nightly 'flush and move'. Recreate your 'prior' tables as partitioned tables that have just ONE range partition; a MAXVALUE partition that covers ALL data. Then each night you would:
    1. TRUNCATE the prior table
    2. Do an EXCHANGE partition between the 'current' table and the associated 'prior' table. Very fast, metadata only - no data actually gets moved.
    3. Load the 'current' table with new data.
    The above process avoid any actual data movement between the 'current' and 'prior' tables.
    Not picking on you but you also haven't said how that new daily 'current' data is being used. If the only reason you are loading it into a table is to compare it to yesterday's data you could just do that with XML like I mentioned above.
    Or you could load the XML itself into a table (e.g. XMLTYPE) and uses Oracle's built-in XDB fuctionality and do the XML comparison 'inside' the database. Then load a standard heap table from the XML table when you need to.
    Maybe the above helps explain why the more info we have about the actual end-to-end problem you have the more options we can suggest for dealing with it. You are the only one that can determine if an option is viable for your particular use case and constraints.
    Updated to add links to Oracle's XML functionality
    See the XMLDiff function that you can use IN the database if you load the XML files themselves. From the SQL Language doc
    http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions241.htm#SQLRF20025
    >
    Purpose
    The XMLDiff function is the SQL interface for the XmlDiff C API. This function compares two XML documents and captures the differences in XML conforming to an Xdiff schema. The diff document is returned as an XMLType document.
    For the first two arguments, specify the names of two XMLType documents.
    For the integer, specify a number representing the hashLevel for a C function XmlDiff. If you do not want hashing, set this argument to 0 or omit it entirely. If you do not want hashing, but you want to specify flags, then you must set this argument to 0.
    For string, specify the flags that control the behavior of the function. These flags are specified by one or more names separated by semicolon. The names are the same as the names of constants for XmlDiff function.
    See Also:
    Oracle XML Developer's Kit Programmer's Guide for more information on using this function, including examples, and Oracle Database XML C API Reference for information on the XML APIs for C
    Examples
    The following example compares two XML documents and returns the difference as an XMLType document:
    >
    See Oracle' own XML Developer's Kit for out-of-the-box functionality for 'diffing' XML documents:
    http://docs.oracle.com/cd/E11882_01/appdev.112/e23582/adx_c_diff.htm
    >
    21 Determining XML Differences Using CThe Oracle XDK includes components that help you to determine the differences between the contents of two XML documents and then to apply the differences (patch) to one of the XML documents.
    This chapter contains these topics:
    Overview of XMLDiff in C
    Using XmlDiff
    Using XmlPatch
    Using XmlHash
    Overview of XMLDiff in C
    You can use Oracle XmlDiff to determine the differences between two similar XML documents. XmlDiff generates an Xdiff instance document that indicates the differences. The Xdiff instance document is an XML document that conforms to an XML schema, the Xdiff schema.
    You can then use XmlPatch, which takes the Xdiff instance document and applies the changes to other documents. This can be used to apply the same changes to a large number of XML documents.
    XmlDiff only supports the DOM API for input and output.
    XmlPatch also supports the DOM for the input and patch documents.
    XmlDiff and XmlPatch can be used through a C API or a command line tool, and they are exposed by two SQL functions.
    An XmlHash C API is provided to compute the hash value of an XML tree or subtree. If hash values of two trees or subtrees are equal, the trees are identical to a very high probability.
    >
    Did you notice that part about 'XmlDiff generates an Xdiff instance document that indicates the differences'? That is EXACTLY what your initial question was asking about, albeit from a DB perspective.
    But XML is XML, DIFF is DIFF, a date/number/text are all strings. So XML 'database data' works the same as XML 'test or complex hierarchy' data.
    Here is a pretty good writeup of how to do XML diff. See the XMLDIFF2 section for the best Oracle sample:
    http://ellebaek.wordpress.com/2011/02/01/comparing-xml-in-oracle/
    >
    XMLDIFF2
    The algorithm in our extended XMLDIFF function that we’re going to call XMLDIFF2 is:
    1.Prepare CLOB variable for constructing the difference XML.
    2.Find minimum number of leading elements that form primary key values (unique lookup).
    3.Look for primary key values in XML1 not present in XML2: These primary key values have been deleted.
    4.Look for primary key values in XML2 not present in XML1: These primary key values have been inserted.
    5.Diff all common primary key values, ie in both XML1 and XML2.
    6.Return NULL if no differences found.

  • Node refnum comparison (XML parser)

    Hello,
    I am trying to parse an XML document (actually an Open Office doc) with the LabVIEW 2009 built-in XML Parser. My problem is to identify if two Nodes are actually refering to the same point in the XML or not. For example:
    I do a search for specific table cells. The result is an array of Nodes. I want to know if they are on the same table row. So I go up to the first "table row" parent, of which I get the reference. Now I would like to compare two of these parent "row" references, to check if they refer to the same table row. Use of the "equal" LabVIEW function seems not to work (always pretends the reference is different, even if pointing to the same table row actually).
    Any idea ?
    Vincent

    Hello,
    Thank you for your interest for the topic. Here is a small example, which is described here:
    Assume you have an XML with following content:
    <XML>
    <Parent>
         <Child name="A1">
              <Feature />
         </Child>
         <Child name="A2">
              <NoFeature />
         </Child>
    </Parent>
    <Parent>
         <Child name="B1">
              <Feature />
         </Child>
         <Child name="B2">
              <NoFeature />
         </Child>
    </Parent>
    </XML>
    Let's say I need to find all the <Feature> nodes and check whether or not they belong to the same <Parent>. If I look for all the <Feature> nodes by sequentially parsing the whole XML (with a combination of "Next Sibling" and "Next Child" navigation), I will certainly know when I switch from one <Parent> instance to the other one, but this is very inefficient for large XML. I have chosen to use the following method instead:
    - with the "Get Elements by Tag Name Array" method for the XML document (DUXGetElementsByTagName), I get an array of all the <Feature> nodes in the document. These are node references to <Child name="A1"/> and <Child name="B2"/> in the above example.
    - from both of these nodes I go up to successive parents until I find the <Parent> node reference.
    - now I have two different references to <Parent> nodes. I am almost over, I just need to check whether these are the same <Parent> node, or if they are different instances of a <Parent> node (as it is the case in the above example).
    How can I do this last step ? Comparing the node references directly with the general "Equal?" built-in LabVIEW function does not work (result is always FALSE, even if both node references point to the same node instance). What is missing here is a sort of "IsSameNode" method, with two node references as inputs, and a boolean as output, that would just return TRUE if both references are pointing to the same node in the XML...
    Hope this helps.
    Best regards,
    Vincent
    Attachments:
    Demo_XML_Parser.zip ‏25 KB

  • 2 XML data comparison

    Hi,
    I want to compare 2 xml data and identify the difference in the values enclosed inside the tags and log it across in a table.Please let me know how to compare 2 xml files in Oracle using pl/sql code.
    P.S:
    I am having Oracle 10.2 release
    Thanks,
    Vijay

    It is certainly possible,
    To give you a confidence ,am saying this statement
    I have seen and worked with complex template involving multiple xml, templates etc..
    drop the xml's and template and description of what is the requirement to my id.
    we will work out ;)

  • Xml string comparison

    Hi All
    I have 2 xml strings as shown below. (Each set is in a string)
    <set>
    <item table_name='tname1' column_name='colname1'>34</item>
    <item table_name='tname1' column_name='colname2'>35</item>
    <item table_name='tname3' column_name='colname1'>36</item>
    <item table_name='tname1' column_name='colname4'>37</item>
    <item table_name='tname2' column_name='colname1'>38</item>
    <item table_name='tname1' column_name='colname5'>39</item>
    </set>
    <set>
    <item table_name='tname1' column_name='colname1'>34</item>
    <item table_name='tname1' column_name='colname2'>36</item>
    <item table_name='tname3' column_name='colname1'>38</item>
    <item table_name='tname1' column_name='colname4'>mmm</item>
    <item table_name='tname2' column_name='colname1'>38</item>
    <item table_name='tname1' column_name='colname5'>50</item>
    </set>
    I have a table with 3 fields:
    TableName, ColumnName, Inc_Exc
    tname1, column1, I
    tname1, column2, E
    tname3, column1, I
    I need to write to a file that...
    The two sets are identical if all fields in the table that has inc_exc flag set to I are same.
    In the above example I have to say it is different because tname3 and column name1 has an include flag but has different values.
    Please note that the sets would have been similar if tname3 and colname1 has same value. Even though other values may differ.
    I do not have to take values for which there in entry in my database table.
    Any ideas how to do this....
    Code sample is appreciated, however if basic idea is given I can code it myself.
    Thanks much
    bib

    But this is just basic Java programming, nothing XML-related.
    if (lastChunk != prevChunk)Don't use == (or !=) to compare the contents of two String objects. Always use the equals() method, otherwise you are just comparing to see if they are (or aren't) the same object. Two different String objects can contain the same contents. In your case:
    if (! lastChunk.equals(prevChunk))with the appropriate checks for null, if necessary.

  • InDesign XML Hierarchy comparison

    Hi all,
    I need the logic of comparing the xml hierarchy between two documents, is there any possibility to do this in InDesign Javascript.
    Using InDesign CS5.5/Windows/Javascript.
    Please let me know if any easy tricks to achieive this task.
    Regards,
    Karpanai.

    I just posted a question about this ( http://forums.adobe.com/thread/844501?tstart=0 ) due to the same problem. Goes for CS4 as well, but only on Mac. I have not observed similar problems in Windows.
    My href paths looks like this in the XML file:
    file:///filename.jpg
    and I've also tried
    file://filename.jpg
    So after I've located the folder and the first image I would expect InDesign to go on placing images from that folder, just as it does in Windows.
    A possible workaround would be to put the XML file to import into the same folder as the images.
    Best regards,
    Andreas

  • XML DB capability comparison 91 & 10g

    Can someone let me know whether a document/thread/support document exists which shows a comparison of capability "on the tin" between 9i and 10g please?
    Thanks
    Dave

    Most of the time, the documents on OTN have a "What's new in...(oracle version number)" For instance in the Oracle database SQL Reference 10g Release 2"Guide (http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/wnsql.htm#sthref11). Some summeries are collected by enthousiast like on http://www.orafaq.com (differences in init.ora parameters). As far as I know there is not a "complete" summery on the specific context "XMLDB", or at least i have not seen it yet. On itself this is almost to much (and overkill) to summerize this. Most of it is in a short form available like in the Oracle® Database New Features Guide
    10g Release 2 (10.2) --> http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14214/toc.htm.
    Work through this and then go back in time ;-) (10gR1--> 9.2 --> 9)

  • Xml file comparison

    hi all,
    can anybody help in coding for comparing two xml files which are the outputs of OCR system that we r developing

    Maybe.

  • Evaluating XML data for comparison

    Does anyone know if it is possible to evaluate an xml node to see if it holds a specific value, and if so how?
    I am trying to do something like this...
    Set myChild = myRoot.evaluateXPathExpression("//collections/page/pnum")
    if myChild(1) = 1 THEN
         [do something]
    Else
         [do something else]
    End if
    I keep getting  a "Object does not support this property or method" error on the first line of the if statement.
    If I placeXML into a text frame I can get the value of myChild(1), so I know the XPath is correct and there is something there, I just can't figure out how to use it.
    That particular node should hold the value of 1.
    I am using VB and CS5.5, but javascript answers/ examples are fine.
    thanks

    I got it figured out.  If anyone else cares to know, it goes like this...
    if myChild(1).contents = 1 THEN

Maybe you are looking for

  • Error regarding File content conversion

    Hello all, I am getting the below mentioned error, com.sap.aii.af.ra.ms.api.MessagingException: Exception in XML Parser (format problem?):'java.lang.Exception: Message processing failed in XML parser: 'java.lang.Exception: Consistency error: more fie

  • Can you filter results by step type?

    Hello all, I was wondering if it's possible to filter report results by the step type. I currenly have it filtered as Result.Status == "Passed" || Result.Status == "Failed. This is fine, except I would like the user to be able to select whether or no

  • HT1451 Many of my song files aren't being located by Itunes.

    My media folder is correctly located and all my music is stored in the correct place.  I store it all on an external hard drive. If I double-click each individual song it reinstates on the Itunes list as a second entry. Please help.

  • I made a new apple account and signed in on my ipod. But now I can't buy any in-app purchases.

    It says 'Your purchase could not be completed' And then 'Failed to connect to itunes store' What should I do? I have tried re installing the app and restarting the  ipod. Syncing it with the right itunes account. Everything. Considering a restore but

  • Spline Engine returns zero with all possible inputs

    Hello, The Spline Engine in my FPGA code for my controller appears to not be working under any inputs. I have set both reset position and spline data updated to TRUE and made the spline data output equivalent to the highest possible number. The docum