Test-Xml Cmdlet - Bug?

Topics: User Forum
May 7, 2016 at 5:08 PM
I'm trying to validate so-called ONIX files against an .xsd XML schema and was happy to find the Test-Xml commandlet. However, regardless of the input file I always get an error (first line translated from German)
Test-Xml $inputFile -SchemaPath "C:\ONIX21local\2.1\ONIX_BookProduct_Release2.1_short.xsd"
Test-Xml : The Type 'http://www.editeur.org/onix/2.1/reference:TextFormatCode' is not a simple type or was not declared.
In J:\_Team\KlugB\Powershell-Skripte\ONIX Validator.ps1:19 Zeichen:5
+     Test-Xml $inputFile -SchemaPath "J:\_Team\KlugB\ONIX21local\2.1\ONIX_BookPro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Test-Xml], XmlSchemaValidationException
    + FullyQualifiedErrorId : System.Xml.Schema.XmlSchemaValidationException,Pscx.Commands.Xml.TestXmlCommand
I assume it might have to do with the fact that the .xsd includes 2 other .xsd's.

I downloaded the .xsd from EDItEUR

Sample ONIX-XML files can be found on http://www.penguinrandomhouse.biz/vendors/rhi_datafeeds (these files require the [...]short.xsd schema)

I also tried invoking Test-Xml with all three involved schemas.

I'd be very grateful for a hint or a bugfix - if applicable.

May 7, 2016 at 7:40 PM
I see this note in the ONIX zip readme.txt:
A number of software application frameworks, including Microsoft .NET, cannot use the ONIX Release 2.1 Schema in its original form released in November 2004, due to the inability of some XML Schema Parsers to handle non-deterministic content models.
And Test-Xml uses .NET to validate the schema.
May 7, 2016 at 9:11 PM
Edited May 7, 2016 at 9:12 PM
My guess was that this is no longer the "original form". The release notes in the .xsd say
2005-03-16: Schema corrected to eliminate non-deterministic models
Doesn't that mean, that this should be fixed meanwhile?
May 8, 2016 at 10:28 PM
The DTDs don't work for me -- they return 404's, so it will not work, unless you remove the DTD from the XML document.

Other than that, the problem is simply that the main xsd includes other xsd files -- you need to set-location to the folder where the XSD are (set [Environment]::CurrentDirectory to it) ... then, something like this worked for me:
ls ..\sample_files_and_onix_guide\*.XML | Test-Xml -schema ONIX_BookProduct_Release2.1_short.xsd -EnableDtd
You can of course pass the XML file as -Path ...
May 8, 2016 at 10:43 PM
@jaykul Thanks! I hit the 404 on the DTD and punted (my wife's birthday was yesterday and had a few things to do). Nice sleuthing.
May 12, 2016 at 9:53 PM
Sorry, I forgot to mention that Editeur took the DTD down. But the DTD is not the problem. Even when I remove the DTD declaration from the XML document, I still get the same error. What I have tried:
  1. I put all .xsd files in C:\XML
  2. I put even the XML file in C:\XML
Set-Location C:\XML
Test-Xml .\PRH-20141201_101251-PG-NA-PHYSICAL-SAMPLE-21.XML -SchemaPath .\ONIX_BookProduct_Release2.1_short.xsd -EnableDtd
Tried different XMLs, too. I am despairing. What am I missing?

Additional questions:
  1. Do I need the -EnableDtd switch when I'm only using .xsd schemas?
  2. Can I force xsd validation if I leave the invalid DTD in the XML? (unfortunately most ONIX files still have this DTD in the header)
May 12, 2016 at 11:19 PM
do this:
Set-Location C:\XML
[Environment]::CurrentLocation = $PWD
Test-Xml .\PRH-20141201_101251-PG-NA-PHYSICAL-SAMPLE-21.XML -SchemaPath .\ONIX_BookProduct_Release2.1_short.xsd -EnableDtd
May 13, 2016 at 9:37 AM
We are getting closer.
[Environment]::CurrentLocation = $PWD
did not work for me. I used
[Environment]::CurrentDirectory = $PWD

What happens now is that Test-Xml always results True, even if I remove e.g. the <a001> Element, which is mandatory. I tried the -Verbose switch which reveals a warning for every element type found in the XML. It seems that the XSD's are still not parsed correctly.

Any ideas?
May 30, 2016 at 3:36 PM