kskchs Posted April 22, 2013 Posted April 22, 2013 Hi All, I am new to this community and my requirement is to compare two Soap XMLs. Can anyone here would be able to help?
water Posted April 22, 2013 Posted April 22, 2013 If you only need a text comparison I would use WinMerge. There is a XMLDOM UDF available but I'm not sure you can work with two XML files at the same time. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
jdelaney Posted April 22, 2013 Posted April 22, 2013 Not sure about the soap wrappers, but the xml can be done using a recursive function (using .childNodes)...are the expected to be exactly the same? just as an example (not recursive though): $sXMLBeginWrap = '<?xml version="1.0"?><items>' $sXML = '<img><a>&SomeValue</a></img>' $sXMLEndWrap = "</items>" $oXML = ObjCreate("Microsoft.XMLDOM") $oXML2 = ObjCreate("Microsoft.XMLDOM") $oXML.loadxml($sXMLBeginWrap & $sXML2 & $sXMLEndWrap) ;~ ConsoleWrite($oXML.xml) $oXML2.loadxml($sXMLBeginWrap & $sXML & $sXMLEndWrap) ;~ ConsoleWrite($oXML.xml) $oRoot = $oXML.documentElement $oRoot2 = $oXML.documentElement For $oChild In $oRoot.childNodes $sRootName = $oRoot.nodeName $sChildName = $oChild.nodeName $oChild2 = $oXML2.SelectSingleNode( "/" & $sRootName & "/" & $sChildName ) If $oChild.nodeName = $oChild2.nodeName Then ConsoleWrite("Found Node" & @CRLF) Else ConsoleWrite("Missing Node" & @CRLF) EndIf Next If the order of elements doesn't matter, I would do a nested loop to navigate through both xml structures, and output those that are not in the outside loop...then repeat with switching the xmls: $sXMLBeginWrap = '<?xml version="1.0"?><items>' $sXML = '<img><a>&SomeValue</a></img>' $sXML2 = '<img><a>&SomeValue</a></img>' $sXMLEndWrap = "</items>" $oXML = ObjCreate("Microsoft.XMLDOM") $oXML2 = ObjCreate("Microsoft.XMLDOM") $oXML.loadxml($sXMLBeginWrap & $sXML2 & $sXMLEndWrap) ;~ ConsoleWrite($oXML.xml) $oXML2.loadxml($sXMLBeginWrap & $sXML & $sXMLEndWrap) ;~ ConsoleWrite($oXML2.xml) $oRoot = $oXML.documentElement $oRoot2 = $oXML2.documentElement For $oChild In $oRoot.childNodes ;~ ConsoleWrite($oChild.nodeName & @CRLF) For $oChild2 In $oRoot2.childNodes $bFound = False If ($oChild.nodeName = $oChild2.nodeName) And $oChild.text = $oChild2.text Then $bFound = True ConsoleWrite("Found $oChild node=[" & $oChild.nodeName & "] in $oXML2 node=[" & $oChild2.nodeName & "]." & @CRLF) ExitLoop EndIf Next If Not $bFound Then ConsoleWrite("Unable to find $oChild node=[" & $oChild.nodeName & "] in $oXML2" & @CRLF) EndIf Next Unable to find $oChild node= in $oXML2 Found $oChild node= in $oXML2 node=. Both examples aren't taking into account the attributes...but you can loop through those as well IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
kskchs Posted April 23, 2013 Author Posted April 23, 2013 @water: I have already developed the tool that considers XML files as text files and do comparisio. But our requirement is bit complex than just text comparision.@jdelaney: Thank you for the code. But when I tried to execute the code, I got below error- though I modified the code so that XML will be read from file.Error: >"D:\install\SciTe\..\autoit3.exe" /ErrorStdOut "D:\XMLCompare\04192013\Test4.au3"soapenv:BodyUnable to find $oChild node=[soapenv:Body] in $oXML2>Exit code: 0 Time: 0.222Modified code:$sXMLBeginWrap = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body<ns7:PayLoad xmlns:ns2="http://services.XXXXXXXXXXXXXX.com/"><ns7:EBSRequest/><ns7:EBSResponse>'$sXML = 'D:\XMLCompare\XML\TC1.xml'$sXML2 = 'D:\XMLCompare\XML\TC2.xml'$sXMLEndWrap ='</ns7:PayLoad></soapenv:Body></soapenv:Envelope>'$oXML = ObjCreate("Microsoft.XMLDOM")$oXML2 = ObjCreate("Microsoft.XMLDOM")$oXML.loadxml($sXMLBeginWrap & $sXML2 & $sXMLEndWrap);~ ConsoleWrite($oXML.xml)$oXML2.loadxml($sXMLBeginWrap & $sXML & $sXMLEndWrap);~ ConsoleWrite($oXML2.xml)$oRoot = $oXML.documentElement$oRoot2 = $oXML2.documentElement For $oChild In $oRoot.childNodes ConsoleWrite($oChild.nodeName & @CRLF) For $oChild2 In $oRoot2.childNodes $bFound = False If ($oChild.nodeName = $oChild2.nodeName) And $oChild.text = $oChild2.text Then $bFound = True ConsoleWrite("Found $oChild node=[" & $oChild.nodeName & "] in $oXML2 node=[" & $oChild2.nodeName & "]." & @CRLF) ExitLoop EndIf Next If Not $bFound Then ConsoleWrite("Unable to find $oChild node=[" & $oChild.nodeName & "] in $oXML2" & @CRLF) EndIfNextSample XML:<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <ns7:PayLoad xmlns:ns2="http://services.XXXXXXXXXXXXXX.com/"> <ns7:EBSRequest/> <ns7:EBSResponse> <Response> <DynamicData> <Node1>123456</Node1> <Node2>23456</Node2> <Node3>3456</Node3> <Node4>5</Node4> <Node5> <SubNode1>ABC+DE(F</SubNode1> <SubNode2/> <SubNode3>XYZ</SubNode3> <SubNode4>19851201</SubNode4> <SubNode5>M</SubNode5> <SubNode6>Male</SubNode6> <SubNode7>OH</SubNode7> </Node5> </DynamicData> </Response> </ns7:PayLoad> </soapenv:Body></soapenv:Envelope>Could you please help me?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now