Loading ...
Sorry, an error occurred while loading the content.
 

Re: [rng-users] Schema with

Expand Messages
  • Jirka Kosek
    ... Schematron validation is pretty easy in PHP as you can transform Schematron in XSLT (and sorry for Czech comments, but OP will understood):
    Message 1 of 9 , May 14, 2013
      On 14.5.2013 12:04, Miloslav Hůla wrote:

      > I'm doing validation in PHP where support of Schematron is poor and
      > difficult. I'll do additional validation on higher level.

      Schematron validation is pretty easy in PHP as you can transform
      Schematron in XSLT (and sorry for Czech comments, but OP will understood):

      <?php
      Header("Content-type: text/plain; charset=utf-8");

      // načtení schématu
      $sch = DOMDocument::load("../schema/zamestnanci.sch");

      // načtení stylu pro převod Schematronu na XSLT
      $sch2xslt = DOMDocument::load("../tools/skeleton1-5.xsl");

      // vytvoření procesoru XSLT
      $proc = new xsltprocessor();
      $proc->importStylesheet($sch2xslt);

      // vytvoření XSLT stylu implementujícího schematronové kontroly
      $validator = $proc->transformToDoc($sch);

      // načtení dokumentu k validaci
      $doc = DOMDocument::load("../schema/zamestnanci-chyba.xml",
      LIBXML_NOENT|LIBXML_DTDLOAD|LIBXML_DTDATTR);

      // nastavení validátoru jako stylu na procesoru XSLT
      $proc->importStylesheet($validator);

      // validace oproti Schematronu
      $vysledek = $proc->transformToDoc($doc);

      // zjištění a případné vypsání chyb
      if ($vysledek->textContent == "")
      {
      echo "Dokument je validní oproti Schematronu.";
      }
      else
      {
      echo "Dokument není validní.\n";
      echo $vysledek->textContent;
      }

      ?>

      --
      ------------------------------------------------------------------
      Jirka Kosek e-mail: jirka@... http://xmlguru.cz
      ------------------------------------------------------------------
      Professional XML consulting and training services
      DocBook customization, custom XSLT/XSL-FO document processing
      ------------------------------------------------------------------
      OASIS DocBook TC member, W3C Invited Expert, ISO JTC1/SC34 rep.
      ------------------------------------------------------------------
      Bringing you XML Prague conference http://xmlprague.cz
      ------------------------------------------------------------------
    • Miloslav Hůla
      ... I was reading about that in your book. But it is not so straightforward like $doc- relaxNGValidate(). Seems to me, it is about XSLT support. Even if it
      Message 2 of 9 , May 14, 2013
        >> I'm doing validation in PHP where support of Schematron is poor and
        >> difficult. I'll do additional validation on higher level.
        >
        > Schematron validation is pretty easy in PHP as you can transform
        > Schematron in XSLT.

        I was reading about that in your book. But it is not so straightforward
        like $doc->relaxNGValidate(). Seems to me, it is about XSLT support.

        Even if it works well, it brings new dependency on XSL PHP extension and
        adds memory stress. Due to that, I cannot use it in my app.

        Is there any way, how to validate by Relax NG containing Schematron? Or
        I must extract Schematron namespace and do it as you wrote?

        Thank you, Miloslav
      • Jirka Kosek
        ... There are some Java libraries supporting embeded Schematron in RELAX NG, but with PHP you have to extract Schematron into separate schema, then create
        Message 3 of 9 , May 14, 2013
          On 14.5.2013 16:39, Miloslav Hůla wrote:

          > Is there any way, how to validate by Relax NG containing Schematron? Or
          > I must extract Schematron namespace and do it as you wrote?

          There are some Java libraries supporting embeded Schematron in RELAX NG,
          but with PHP you have to extract Schematron into separate schema, then
          create transformation from it using Schematron skeleton and then run
          this transformation for validation.

          Jirka

          --
          ------------------------------------------------------------------
          Jirka Kosek e-mail: jirka@... http://xmlguru.cz
          ------------------------------------------------------------------
          Professional XML consulting and training services
          DocBook customization, custom XSLT/XSL-FO document processing
          ------------------------------------------------------------------
          OASIS DocBook TC member, W3C Invited Expert, ISO JTC1/SC34 rep.
          ------------------------------------------------------------------
          Bringing you XML Prague conference http://xmlprague.cz
          ------------------------------------------------------------------
        • Daniel Dehennin
          ... Hello, I m replying to this thread since it seems to be what I m confronted to. ... So, If I understand correctly, here is what I have: - There is an
          Message 4 of 9 , Jul 11
            George Cristian Bina <george@...> writes:

            > Hi Miloslav,

            Hello,

            I'm replying to this thread since it seems to be what I'm confronted to.


            > Please see
            > https://www.oasis-open.org/committees/relax-ng/spec-20011203.html#interleave-restrictions
            >
            > This restriction basically say that you cannot interleave two (or more)
            > elements with the same name, param in your case.
            >
            > I cannot think of a way to obtain what you want in Relax NG.
            > As options you have
            > - set an order on your parameters, add the required parameters first
            > and then the optional ones, similar with your model if you delete the
            > interleave tags.
            > - use a more relaxed model in Relax NG and then use Schematron or some
            > other mechanism to enforce your additional constraints. Schematron can
            > be also embedded in Relax NG.

            So, If I understand correctly, here is what I have:

            - There is an application which produce an XML like:

            #+begin_src xml
            <?xml version="1.0" encoding="UTF-8"?>
            <Root>
            <attr name="foo1">
            <value>1</value>
            </attr>
            <attr name="foo2">
            <value>1</value>
            </attr>
            <attr name="foo3">
            <value>1</value>
            </attr>
            <attr name="foo4">
            <value>1</value>
            </attr>
            </Root>
            #+end_src

            - I tried the following RNC shema:

            #+begin_src rnc
            grammar {
            start = Root

            Root = element Root { attributes }

            attributes &= foo1
            attributes &= foo2
            attributes &= foo3
            attributes &= foo4

            foo1 = element attr {
            attribute name { "foo1" },
            element value { xsd:integer }
            }

            foo2 = element attr {
            attribute name { "foo2" },
            element value { xsd:integer }
            }

            foo3 = element attr {
            attribute name { "foo3" },
            element value { xsd:integer }
            }

            foo4 = element attr {
            attribute name { "foo4" },
            element value { xsd:integer }
            }

            }
            #+end_src

            But it does not work as expected in my editor, it reports an error when
            the foo1 is after foo2 in the XML.

            This is because I can't interleave on the same “attr” element, right?

            I need to do something like:

            #+begin_src rnc
            grammar {
            start = Root

            Root = element Root { attribute+ }

            attribute |= foo1
            attribute |= foo2
            attribute |= foo3
            attribute |= foo4

            foo1 = element attr {
            attribute name { "foo1" },
            element value { xsd:integer }
            }

            foo2 = element attr {
            attribute name { "foo2" },
            element value { xsd:integer }
            }

            foo3 = element attr {
            attribute name { "foo3" },
            element value { xsd:integer }
            }

            foo4 = element attr {
            attribute name { "foo4" },
            element value { xsd:integer }
            }

            }
            #+end_src

            The ideal but I can dream would be to ask the 3party software to produce
            XML like:

            #+begin_src xml
            <?xml version="1.0" encoding="UTF-8"?>
            <Root>
            <foo1>
            <value>1</value>
            </foo1>
            <foo2>
            <value>1</value>
            </foo2>
            <foo3>
            <value>1</value>
            </foo3>
            <foo4>
            <value>1</value>
            </foo4>
            </Root>
            #+end_src

            Am I right?

            Regards.
            --
            Daniel Dehennin
            Récupérer ma clef GPG: gpg --recv-keys 0xCC1E9E5B7A6FE2DF
            Fingerprint: 3E69 014E 5C23 50E8 9ED6 2AAD CC1E 9E5B 7A6F E2DF
          • George Bina
            Yes, you cannot use interleave on multiple patterns that use the same element name. You can relax your model in Relax NG and enforce the additional constraint
            Message 5 of 9 , Jul 12
              Yes, you cannot use interleave on multiple patterns that use the same
              element name.
              You can relax your model in Relax NG and enforce the additional
              constraint from a Schematron schema.

              Best Regards,
              George
              --
              George Cristian Bina
              <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
              http://www.oxygenxml.com

              On 12/07/17 00:41, Daniel Dehennin daniel.dehennin@...
              [rng-users] wrote:
              > George Cristian Bina <george@...> writes:
              >
              >> Hi Miloslav,
              >
              > Hello,
              >
              > I'm replying to this thread since it seems to be what I'm confronted to.
              >
              >
              >> Please see
              >> https://www.oasis-open.org/committees/relax-ng/spec-20011203.html#interleave-restrictions
              >>
              >> This restriction basically say that you cannot interleave two (or more)
              >> elements with the same name, param in your case.
              >>
              >> I cannot think of a way to obtain what you want in Relax NG.
              >> As options you have
              >> - set an order on your parameters, add the required parameters first
              >> and then the optional ones, similar with your model if you delete the
              >> interleave tags.
              >> - use a more relaxed model in Relax NG and then use Schematron or some
              >> other mechanism to enforce your additional constraints. Schematron can
              >> be also embedded in Relax NG.
              >
              > So, If I understand correctly, here is what I have:
              >
              > - There is an application which produce an XML like:
              >
              > #+begin_src xml
              > <?xml version="1.0" encoding="UTF-8"?>
              > <Root>
              > <attr name="foo1">
              > <value>1</value>
              > </attr>
              > <attr name="foo2">
              > <value>1</value>
              > </attr>
              > <attr name="foo3">
              > <value>1</value>
              > </attr>
              > <attr name="foo4">
              > <value>1</value>
              > </attr>
              > </Root>
              > #+end_src
              >
              > - I tried the following RNC shema:
              >
              > #+begin_src rnc
              > grammar {
              > start = Root
              >
              > Root = element Root { attributes }
              >
              > attributes &= foo1
              > attributes &= foo2
              > attributes &= foo3
              > attributes &= foo4
              >
              > foo1 = element attr {
              > attribute name { "foo1" },
              > element value { xsd:integer }
              > }
              >
              > foo2 = element attr {
              > attribute name { "foo2" },
              > element value { xsd:integer }
              > }
              >
              > foo3 = element attr {
              > attribute name { "foo3" },
              > element value { xsd:integer }
              > }
              >
              > foo4 = element attr {
              > attribute name { "foo4" },
              > element value { xsd:integer }
              > }
              >
              > }
              > #+end_src
              >
              > But it does not work as expected in my editor, it reports an error when
              > the foo1 is after foo2 in the XML.
              >
              > This is because I can't interleave on the same “attr” element, right?
              >
              > I need to do something like:
              >
              > #+begin_src rnc
              > grammar {
              > start = Root
              >
              > Root = element Root { attribute+ }
              >
              > attribute |= foo1
              > attribute |= foo2
              > attribute |= foo3
              > attribute |= foo4
              >
              > foo1 = element attr {
              > attribute name { "foo1" },
              > element value { xsd:integer }
              > }
              >
              > foo2 = element attr {
              > attribute name { "foo2" },
              > element value { xsd:integer }
              > }
              >
              > foo3 = element attr {
              > attribute name { "foo3" },
              > element value { xsd:integer }
              > }
              >
              > foo4 = element attr {
              > attribute name { "foo4" },
              > element value { xsd:integer }
              > }
              >
              > }
              > #+end_src
              >
              > The ideal but I can dream would be to ask the 3party software to produce
              > XML like:
              >
              > #+begin_src xml
              > <?xml version="1.0" encoding="UTF-8"?>
              > <Root>
              > <foo1>
              > <value>1</value>
              > </foo1>
              > <foo2>
              > <value>1</value>
              > </foo2>
              > <foo3>
              > <value>1</value>
              > </foo3>
              > <foo4>
              > <value>1</value>
              > </foo4>
              > </Root>
              > #+end_src
              >
              > Am I right?
              >
              > Regards.
              >
            Your message has been successfully submitted and would be delivered to recipients shortly.