Obviously we could use a DTD or a schema to validate the message output, but this approach wouldn't allow us to distinguish between valid XML with correct content (e.g. The failure message indicates both what the difference is and the XPath locations of the nodes that were being compared: .
Alternatively there are static methods on the XMLUnit class that can be called directly.
A Power Shell script seemed like a natural fit for this kind of thing. I have created the following function which uses some of the techniques described here. I had to validate XML documents before at various times however I always found the line number to be 0.
The Power Shell Community Extensions has a Test-Xml cmdlet.
The following test illustrates the use of a custom implementation as two pieces of XML are compared.
Using recursion it navigates through the nodes in the control XML DOM, and determines which node in the test XML DOM qualifies for comparison to the current control node.
I'd like to be able to easily integrate it into automated build scripts. the solution of (wangzq) is working on PS2 and PS3!!
Didn't want to have to compile an app just to do this. Xml Schema]:: Read($schema Reader, $Validation Event Handler) $xml. anyone who needs an xml validation on PS3, can use this (based on wangzq's function) I have created a separate Power Shell file which can perform XSD validation on XML files with an inline schema reference. Download and howto are available on https://knowledge.zomers.eu/Power Shell/Pages/How-to-validate-XML-against-an-XSD-schema-using-Power function Test-Xml #example calling/useage code follows: $erroractionpreference = 'stop' Set-strictmode -version 2 $valid = @(Test-Xml -inputfile $inputfile -schemafile $XSDPath ) write-host "Found ($($valid.count)) errors" if ($valid.count) I realise this is an old question however I tried the answers provided and could not get them to work successfully in Powershell.I couldn't have added the twitter feed nearly as easily without this code.I'm afraid that I butchered the output unmercifully in order to get it into my SQL instead of on the page, but the underlying code worked great and was easy to understand and modify. One quick question: Is it possible for me to remove the "Author" field from the output, and if so, how is that accomplished?The test below illustrates how the use of these classes: One of the key points about using XPaths with HTML content is that extracting values in tests requires the values to be identifiable.(This is just another way of saying that testing HTML is easier when it is written to be testable.) In the previous example id attributes were used to identify the list item values that needed to be testable, however class attributes or span and div tags can also be used to identify specific content for testing. It is an open source project hosted at that grew out of a need to test a system that generated and received custom XML messages. The advantage of this approach is that you can specify a different parser class for control and test XML and change the current parser class at any time in your tests, should you need to make assertions about the compatibility of different parsers. Document Builder Factory Impl"); Test Parser("org.apache. Document Builder Factory Impl"); SAXParser Factory("org.apache. SAXParser Factory Impl"); Transformer Factory("org.apache.xalan.processor. Transformer Factory Impl"); test will pass if the control and test XML are either similar or identical.