Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7531469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:10:48+00:00 2026-05-30T05:10:48+00:00

We’re developing in Java for the most, but we want to integration test (using

  • 0

We’re developing in Java for the most, but we want to integration test (using https://github.com/scottmuc/Pester) our web-services with ms as well. To do this I’m writing powershell scripts that connects to a web-service and compares the response to xml that I’ve loaded from a file.

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$instance = New-WebServiceProxy -Uri "https://localhost:7002/service?WSDL" -Namespace "myspace"
$instance.Credentials = new-object System.Net.NetworkCredential("user", "pass")
...
$reply = $instance.fetchInformation($inputA, $inputB)
[xml]$expected = Get-Content ("expected.xml")
...

However, now I have a $reply that contains objects from the myspace namespace and an $expected that contains an XMLNode. I see two ways I can do this (there are probably many more):

  1. Get the original XML response and compare that. However, I can’t seem to find out how to get that.
  2. Serialise the $expected XML into the myspace namespace objects. Is that possible?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:10:50+00:00Added an answer on May 30, 2026 at 5:10 am

    I ended up with a completely different approach. The two XML’s was quite different from each other so instead I created a custom comparator. This made it possible for me to simply write custom code to ignore uninteresting differences.

    This lead to some pile of crude code that does the job:

    # Assume two arrays of equal length
    Function Zip {
        Param($a1, $a2)
    
        $sum = New-Object object[] $a1.Count
        For ($i = 0; $i -lt $a1.Count; ++$i) {
            $sum[$i] = New-Object object[] 2
            $sum[$i][0] = $a1[$i]
            $sum[$i][1] = $a2[$i]
        }
        Return ,$sum
    }
    
    
    Function XmlChildNodes2List{
        param($nodes)
        $myArray = New-Object object[] 0
        For ($i = 0; $i -lt $nodes.Count; ++$i) {
            $node = $nodes.Item($i)
            If ($node -ne $null) {
                $myArray += $node
            }
        }
        Return ,$myArray
    }
    
    Function ShowContext{
        Param($ctx)
        " at " + $ctx
    }
    
    Function CompareNode{
        Param($o1, $o2, $ctx)
    
        Try {
        Switch ($o1.GetType().Name) {
            "XmlDocument" {
                CompareXml $o1.ChildNodes $o2.ChildNodes
            }
            "XmlChildNodes" {
                $olist1 = XmlChildNodes2List $o1 | Sort
                $olist2 = XmlChildNodes2List $o2 | Sort
                If ($olist1.Count -ne $olist2.Count) {
                    $msg = "Unequal child node count " + ($olist1 -join ",") + " and " + ($olist2 -join ",") + (ShowContext $ctx)
                    throw $msg
                } Else {
                    $list = Zip $olist1 $olist2
                    $value = $true
                    foreach ($item in $list) {
                        if ($value -eq $true) {
                            $value = CompareXml $item[0] $item[1] $ctx
                        }
                    }
                    $value
                }
            }
            "XmlElement" {
                If ($o1.LocalName -eq $o2.LocalName) {
                    If ($o1.LocalName -eq "uninterestingElement" -or $o1.LocalName -eq "uninterestingElement2") {
                        $true
                    } Else {
                        CompareXML $o1.ChildNodes $o2.ChildNodes ($ctx + "/" + $o1.LocalName)
                    }
                } Else {
                    throw ("Element " + $o1.LocalName + " != " + $o2.LocalName + (ShowContext $ctx))
                }
            }
            "XmlDeclaration" {
                $true
            }
            "XmlText" {
                $result = $o1.InnerText.Replace("`r`n","`n")
                $expect = $o2.InnerText.Replace("`r`n","`n")
                # TODO: Hack to remove timezone from expected dates in format 2005-09-01+02:00, the webservice side of the
                # reply to xml-conversion looses them
                If ($expect -match "^(\d{4}-\d\d-\d\d)\+\d\d:\d\d$") {
                    $expect = $Matches[1]
                }
                If ($result -eq $expect) {
                    $true
                } Else {
                    throw ($o1.InnerText + " is not equal to " + $o2.InnerText + (ShowContext $ctx))
                }
            }
            Default {
                throw ("What to do with node " + $o1.GetType().Name + (ShowContext $ctx))
            }
        }
        } Catch [Exception] {
            throw $_
        }
    }
    
    Function CompareXML{
        Param($o1, $o2, $ctx)
    
        If ($o1 -eq $null -and $o2 -eq $null) {
            $true
        } ElseIf ($o1 -eq $null -or $o2 -eq $null) {
            throw ("Response or expected is null")
        } ElseIf ($o1.GetType() -eq $o2.GetType()) {
            CompareNode $o1 $o2 $ctx
        } Else {
            throw ($o1.GetType().Name + " is not " + $o2.GetType().Name + (ShowContext $ctx))
        }
    }
    

    This can then be run on two XML’s like this:

    CompareXML $result $expected ""
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I want to construct a data frame in an Rcpp function, but when I
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.