Validate part of XML file

Questions about XML that are not covered by the other forums should go here.
AndreasT
Posts: 5
Joined: Fri Sep 22, 2017 11:34 am

Validate part of XML file

Post by AndreasT » Fri Apr 23, 2021 4:54 pm

Hello.
This seems to me a noob question, but I cannot find the answer after looking around a bit so sorry if it's obvious.

I have a few XML files that need to be validated and I only have a XSD for the core element of the files. The files also have a header section that wraps the core element.
Is there a way to create a validation scenario that ignores the header and only validates the core element, maybe using XPath?

tavy
Posts: 284
Joined: Thu Jul 01, 2004 12:29 pm

Re: Validate part of XML file

Post by tavy » Mon Apr 26, 2021 12:31 pm

Hello,

No, you cannot use validation scenario to ignore the header element, and associate the XSD schema only with the core element. Probably you can do this from the XSD schema. Maybe you can use a different namespace for the header element, and associate the schema only for that namespace.

Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com

AndreasT
Posts: 5
Joined: Fri Sep 22, 2017 11:34 am

Re: Validate part of XML file

Post by AndreasT » Mon Apr 26, 2021 5:22 pm

Thank you.
They DO have different namespaces so that led me to another approach that I now remember having used earlier on another project.
I've set up a validation scenario with the XSD for the core of the file and set up a catalog to specify the path to the header file, but Oxygen still fails to validate the header part, it cannot locate the elements.
Do I need to do anything else to load the files linked in the catalog?

Is it possible to see a list of the files that Oxygen has loaded during validation and also if there were any errors during load?

tavy
Posts: 284
Joined: Thu Jul 01, 2004 12:29 pm

Re: Validate part of XML file

Post by tavy » Tue Apr 27, 2021 3:37 pm

Hello,

If you do not have an XSD schema for the header, and you want to validate only the core part, I recommend you to use an NVDL schema.
I think you can create a schema something like this:

Code: Select all

<rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0">
    <namespace ns="http://testCore">
        <validate schema="coreSchema.xsd"/>
    </namespace>
    <anyNamespace>
        <allow></allow>
    </anyNamespace>
</rules>
This specifies that the elements from the "http://testCore" namespace will be validated with the coreSchema.xsd, and the elements from other namespaces are allowed.
Then you can associate the NVDL schema in the XML document or use a validation scenario.

Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com

AndreasT
Posts: 5
Joined: Fri Sep 22, 2017 11:34 am

Re: Validate part of XML file

Post by AndreasT » Tue Apr 27, 2021 6:51 pm

Thank you, this solved my problem. :D

Post Reply