GarouDan
GarouDan

Reputation: 3833

How to validate Google Shopping XMLs with RELAX NG?

I'm trying to validate xmls with the RELAX NG structure.

I had tried the variations like these one:

<grammar ns="" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
    <start>
        <element name="rss" version="2.0" xmlns:g="http://base.google.com/ns/1.0">
            <element name="channel">
                <element name="title">
                    <data type="token"/>
                </element>

                <element name="description">
                    <data type="token"/>
                </element>

                <element name="link">
                    <data type="anyURI"/>
                </element>

                <oneOrMore>
                    <element name="item">
                        <element name="g:id">
                            <data type="long"/>
                        </element>

                        <element name="title">
                            <data type="token"/>
                        </element>

The first problem is when interpreting the tag "g:id", for example, I solved putting xmlns:g="http://base.google.com/ns/1.0" at the rss element.

But as we can see at the manual, we need to put version="2.0" at the rss element tag too. But if I try to use

<element name="rss" version="2.0" xmlns:g="http://base.google.com/ns/1.0">

I get errors:

PHP Warning:  DOMDocument::relaxNGValidate(): Unknown attribute version on element in ...

If I use

<element name="rss" xmlns:g="http://base.google.com/ns/1.0">

I have no errors, but version="2.0" is needed by the manual.

How can I solve this?

Upvotes: 1

Views: 426

Answers (1)

GarouDan
GarouDan

Reputation: 3833

I had found myself the solution

Example below:

<grammar ns="" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
    <start>
        <element name="rss" xmlns:g="http://base.google.com/ns/1.0">
            <attribute name="version">
                <data type="decimal"/>
            </attribute>
            <element name="channel">
                <element name="title">
                    <data type="token"/>
                </element>

                <element name="description">
                    <data type="token"/>
                </element>

                <element name="link">
                    <data type="anyURI"/>
                </element>

                <oneOrMore>
                    <element name="item">
                        <element name="g:id">
                            <data type="long"/>
                        </element>

                        <element name="title">
                            <data type="token"/>
                        </element>

Upvotes: 1

Related Questions