Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › RelaxNG XML Schema Issue
New Posts  All Forums:Forum Nav:

RelaxNG XML Schema Issue

post #1 of 4
Thread Starter 
For some reason can't get this code to work. It looks correct to me, but Oxygen tells me it is not valid because:
Code:
Description: a group of attributes must not be repeatable
(section 7.1 of the RELAX NG specification requires that the simplified XML
form of the schema not contain any elements matching the path
oneOrMore//group//attribute)
Severity: Error
Engine name: Jing
Start location line: 79, column: 38                          
If anyone could take a look at it and help me figure out what the heck is wrong I would appreciate it.

presentations2.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="presentations2.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<presentations>
  <presentation date="2013-07-31" length="PT30M">
    <topic genre="Music">PianoML</topic>
    <presenters>
      <name title="Mr." id="Y258">
        <first>Elvis</first>
        <middle>A</middle>
        <last>Presley </last>
      </name>
      <name title="Miss" id="X365">
        <first>Lady</first>
        <last>Gaga</last>
      </name>
    </presenters>
  </presentation>
  <presentation date="2013-08-05" length="PT35M">
    <topic genre="Science">AlienML</topic>
    <presenters>
      <name title="Mr." id="Y007">
        <first>Will</first>
        <last>Smith</last>
      </name>
      <name title="Mr." id="Y360">
        <first>Tommy</first>
        <first>Lee</first>
        <last>Jones</last>
      </name>
    </presenters>
  </presentation>
</presentations>
presentations2.rng
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Define namespaces and libraries  -->
<grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  <!-- Define date attribute of type date globally.  -->
  <define name="dateAtt">
    <attribute name="date">
      <data type="date"/>
    </attribute>
  </define>
  <!-- Define length attribute of type string globally.  -->
  <define name="lengthAtt">
    <attribute name="length">
      <data type="string"/>
    </attribute>
  </define>
  <!-- Define topic element with attribute genre globally.  -->
  <define name="topicElement">
    <ref name="genreAtt"/>
  </define>
  <!-- Define name element with id and title attributes, one or more first name child elements, zero or one middle name child elements, and a last name child element globally.  -->
  <define name="nameElement">
    <ref name="idAtt"/>
    <ref name="titleAtt"/>
    <oneOrMore>
      <element name="first">
        <data type="string"/>
      </element>
    </oneOrMore>
    <optional>
      <element name="middle">
        <data type="string"/>
      </element>
    </optional>
    <element name="last">
      <data type="string"/>
    </element>
  </define>
  <!-- Define title attribute globally. Restrict possible values to Mr. Mrs. Ms. or Miss  -->
  <define name="titleAtt">
    <attribute name="title">
      <choice>
        <value type="token">Mr.</value>
        <value type="token">Mrs.</value>
        <value type="token">Ms.</value>
        <value type="token">Miss</value>
      </choice>
    </attribute>
  </define>
  <!-- Define id attribute of type id globally. Must follow patter or an X or a Y follwed by three digits.  -->
  <define name="idAtt">
    <attribute name="id">
      <data type="token">
        <param name="pattern">[XY]\d{3}</param>
      </data>
    </attribute>
  </define>
  <!-- Define genre attribute globally. Restrict possible values to the choics of Art, Music, Science, or Technology.  -->
  <define name="genreAtt">
    <attribute name="genre">
      <choice>
        <value type="token">Art</value>
        <value type="token">Music</value>
        <value type="token">Science</value>
        <value type="token">Technology</value>
      </choice>
    </attribute>
  </define>
  <!-- Put everything together.  -->
  <start>
    <!-- Root element is presentations  -->
    <element name="presentations">
      <!-- There are zero or more presentation elements each with attributes date and length and elements topic and presenters.  -->
      <zeroOrMore>
        <element name="presentation">
          <ref name="dateAtt"/>
          <ref name="lengthAtt"/>
          <ref name="topicElement"/>
          <!-- The element presenters has one or more name elements.  -->
          <element name="presenters">
            <oneOrMore>
              <!-- Name element is defined globally and has children first middle and last.  -->
              <ref name="nameElement"/>
            </oneOrMore>
          </element>
        </element>
      </zeroOrMore>
    </element>
  </start>
</grammar>
    
CPUMotherboardGraphicsGraphics
Intel Core i7 3770k ASRock Z77 Extreme4 HD667XZWF4 HD667XZWF4 
RAMHard DriveHard DriveOptical Drive
Corsair Vengeance LP Blue 2x8GB CL10 1600MHz Samsung 830 256GB SSD Seagate ST4000DM000 Pioneer BDR-206BDK 
Optical DriveCoolingOSMonitor
LG UH12NS29 Corsair H100i Windows 7 Ultimate x64 Dell U3011 
MonitorMonitorMonitorKeyboard
Dell 2007FP Dell 2007FP 32" 1920x1080 LED TV Logitech MX5500 Revolution 
PowerCase
Corsair HX750 Corsair Carbide 500R 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
Intel Core i7 3770k ASRock Z77 Extreme4 HD667XZWF4 HD667XZWF4 
RAMHard DriveHard DriveOptical Drive
Corsair Vengeance LP Blue 2x8GB CL10 1600MHz Samsung 830 256GB SSD Seagate ST4000DM000 Pioneer BDR-206BDK 
Optical DriveCoolingOSMonitor
LG UH12NS29 Corsair H100i Windows 7 Ultimate x64 Dell U3011 
MonitorMonitorMonitorKeyboard
Dell 2007FP Dell 2007FP 32" 1920x1080 LED TV Logitech MX5500 Revolution 
PowerCase
Corsair HX750 Corsair Carbide 500R 
  hide details  
Reply
post #2 of 4
Quote:
Originally Posted by Gronnie View Post

For some reason can't get this code to work. It looks correct to me, but Oxygen tells me it is not valid because:
Code:
Description: a group of attributes must not be repeatable
(section 7.1 of the RELAX NG specification requires that the simplified XML
form of the schema not contain any elements matching the path
oneOrMore//group//attribute)
Severity: Error
Engine name: Jing
Start location line: 79, column: 38                          
If anyone could take a look at it and help me figure out what the heck is wrong I would appreciate it.

presentations2.xml
Code:
Warning: Spoiler! (Click to show)

 

<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="presentations2.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<presentations>
  <presentation date="2013-07-31" length="PT30M">
    <topic genre="Music">PianoML</topic>
    <presenters>
      <name title="Mr." id="Y258">
        <first>Elvis</first>
        <middle>A</middle>
        <last>Presley </last>
      </name>
      <name title="Miss" id="X365">
        <first>Lady</first>
        <last>Gaga</last>
      </name>
    </presenters>
  </presentation>
  <presentation date="2013-08-05" length="PT35M">
    <topic genre="Science">AlienML</topic>
    <presenters>
      <name title="Mr." id="Y007">
        <first>Will</first>
        <last>Smith</last>
      </name>
      <name title="Mr." id="Y360">
        <first>Tommy</first>
        <first>Lee</first>
        <last>Jones</last>
      </name>
    </presenters>
  </presentation>
</presentations>

 

 

presentations2.rng
Code: Warning: Spoiler! (Click to show)

 

 
<?xml version="1.0" encoding="UTF-8"?>
<!-- Define namespaces and libraries  -->
<grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  <!-- Define date attribute of type date globally.  -->
  <define name="dateAtt">
    <attribute name="date">
      <data type="date"/>
    </attribute>
  </define>
  <!-- Define length attribute of type string globally.  -->
  <define name="lengthAtt">
    <attribute name="length">
      <data type="string"/>
    </attribute>
  </define>
  <!-- Define topic element with attribute genre globally.  -->
  <define name="topicElement">
    <ref name="genreAtt"/>
  </define>
  <!-- Define name element with id and title attributes, one or more first name child elements, zero or one middle name child elements, and a last name child element globally.  -->
  <define name="nameElement">
    <ref name="idAtt"/>
    <ref name="titleAtt"/>
    <oneOrMore>
      <element name="first">
        <data type="string"/>
      </element>
    </oneOrMore>
    <optional>
      <element name="middle">
        <data type="string"/>
      </element>
    </optional>
    <element name="last">
      <data type="string"/>
    </element>
  </define>
  <!-- Define title attribute globally. Restrict possible values to Mr. Mrs. Ms. or Miss  -->
  <define name="titleAtt">
    <attribute name="title">
      <choice>
        <value type="token">Mr.</value>
        <value type="token">Mrs.</value>
        <value type="token">Ms.</value>
        <value type="token">Miss</value>
      </choice>
    </attribute>
  </define>
  <!-- Define id attribute of type id globally. Must follow patter or an X or a Y follwed by three digits.  -->
  <define name="idAtt">
    <attribute name="id">
      <data type="token">
        <param name="pattern">[XY]\d{3}</param>
      </data>
    </attribute>
  </define>
  <!-- Define genre attribute globally. Restrict possible values to the choics of Art, Music, Science, or Technology.  -->
  <define name="genreAtt">
    <attribute name="genre">
      <choice>
        <value type="token">Art</value>
        <value type="token">Music</value>
        <value type="token">Science</value>
        <value type="token">Technology</value>
      </choice>
    </attribute>
  </define>
  <!-- Put everything together.  -->
  <start>
    <!-- Root element is presentations  -->
    <element name="presentations">
      <!-- There are zero or more presentation elements each with attributes date and length and elements topic and presenters.  -->
      <zeroOrMore>
        <element name="presentation">
          <ref name="dateAtt"/>
          <ref name="lengthAtt"/>
          <ref name="topicElement"/>
          <!-- The element presenters has one or more name elements.  -->
          <element name="presenters">
            <oneOrMore>
              <!-- Name element is defined globally and has children first middle and last.  -->
              <ref name="nameElement"/>
            </oneOrMore>
          </element>
        </element>
      </zeroOrMore>
    </element>
  </start>
</grammar>

 

 

 

Quote:

A zeroOrMore element is transformed into a choice between oneOrMore and empty:

<zeroOrMore> p </zeroOrMore>

is transformed into

<choice> <oneOrMore> p </oneOrMore> <empty/> </choice>
.
.
.
A define, oneOrMore, zeroOrMore, optional, list or mixed element is transformed so that it has exactly one child element. If it has more than one child element, then its child elements are wrapped in a group element. Similarly, an element element is transformed so that it has exactly two child elements, the first being a name class and the second being a pattern. If it has more than two child elements, then the child elements other than the first are wrapped in a group element.

The quote above explains the oneOrMore//group part, but I'm still not sure what's giving a transform into <attribute> that then generates your oneOrMore//group//attribute exception.

 

It's also possible that this unwinding is causing some attribute to duplicate.

 

I'm not that familiar with relaxNG (today was the first time I've skimmed the spec)

post #3 of 4
Thread Starter 
Thanks for looking it over. I started over from scratch and got it to work. Here is the working version if you are interested:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<grammar 
    xmlns="http://relaxng.org/ns/structure/1.0"
    xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
    datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
    <!-- Define Date Global -->
    <define name="dateAtt">
        <attribute name="date">
            <data type="date"/>
        </attribute>
    </define>
    <!-- Define Length Global -->
    <define name="lengthAtt">
        <attribute name="length">
            <data type="duration"/>
        </attribute>
    </define>
    <!-- Define Topic Global -->
    <define name="topicElement">
        <element name="topic">
            <data type="string"/>
            <ref name="genreAtt"/>
        </element>
    </define>
    
    <!-- Define Name Global -->
    <define name="nameElement">
        <element name="name">
            <!-- Reference title and id attributes -->
            <ref name="titleAtt"/>
            <ref name="idAtt"/>
            <!-- Define children (one or more first, optional middle, one last name) -->
                <oneOrMore>
                    <element name="first">
                        <data type="string"></data>
                    </element>
                </oneOrMore>
                <optional>
                    <element name="middle">
                        <data type="string"></data>
                    </element>
                </optional>
                <element name="last">
                    <data type="string"></data>
                </element>
        </element>
    </define>
    <!-- Define title attribute global. Restrict values to those enumerated. -->
    <define name="titleAtt">
        <attribute name="title">
            <choice>
                <value type="token">Mr.</value>
                <value type="token">Mrs.</value>
                <value type="token">Ms.</value>
                <value type="token">Miss</value>
            </choice>
        </attribute>
    </define>
    <!-- Define id attribute global. Restrict values to those that start with an X or Y followed by 3 digits -->
    <define name="idAtt">
        <attribute name="id">
            <data type="token">
                <param name="pattern">[XY]\d{3}</param>
            </data>
        </attribute>
    </define>
    <!-- Define genre attribute global. Restrict values to those enumerated. -->
    <define name="genreAtt">
        <attribute name="genre">
            <choice>
                <value type="token">Art</value>
                <value type="token">Music</value>
                <value type="token">Science</value>
                <value type="token">Technology</value>
            </choice>
        </attribute>
    </define>
    <!-- Start element -->
    <start>
        <!-- Root element presentations -->
        <element name="presentations">
            <!-- Followed by zero or more presentation elements. -->
            <zeroOrMore>
                <element name="presentation">
                    <!-- Reference date and length attributes -->
                    <ref name="dateAtt"/>
                    <ref name="lengthAtt"/>
                    <!-- Has child elements topic and presenters -->
                    <ref name="topicElement"/>
                    <element name="presenters">
                        <!-- Presenters has one or more name elements. Name has child elements first, middle, and last (as defined globally) -->
                        <oneOrMore>
                            <ref name="nameElement"/>
                        </oneOrMore>
                    </element>
                </element>
            </zeroOrMore>
        </element>
    </start>
    <!-- End start element -->
</grammar>
<!-- End of document -->
    
CPUMotherboardGraphicsGraphics
Intel Core i7 3770k ASRock Z77 Extreme4 HD667XZWF4 HD667XZWF4 
RAMHard DriveHard DriveOptical Drive
Corsair Vengeance LP Blue 2x8GB CL10 1600MHz Samsung 830 256GB SSD Seagate ST4000DM000 Pioneer BDR-206BDK 
Optical DriveCoolingOSMonitor
LG UH12NS29 Corsair H100i Windows 7 Ultimate x64 Dell U3011 
MonitorMonitorMonitorKeyboard
Dell 2007FP Dell 2007FP 32" 1920x1080 LED TV Logitech MX5500 Revolution 
PowerCase
Corsair HX750 Corsair Carbide 500R 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
Intel Core i7 3770k ASRock Z77 Extreme4 HD667XZWF4 HD667XZWF4 
RAMHard DriveHard DriveOptical Drive
Corsair Vengeance LP Blue 2x8GB CL10 1600MHz Samsung 830 256GB SSD Seagate ST4000DM000 Pioneer BDR-206BDK 
Optical DriveCoolingOSMonitor
LG UH12NS29 Corsair H100i Windows 7 Ultimate x64 Dell U3011 
MonitorMonitorMonitorKeyboard
Dell 2007FP Dell 2007FP 32" 1920x1080 LED TV Logitech MX5500 Revolution 
PowerCase
Corsair HX750 Corsair Carbide 500R 
  hide details  
Reply
post #4 of 4
Thread Starter 
oops, duplicate post.....
    
CPUMotherboardGraphicsGraphics
Intel Core i7 3770k ASRock Z77 Extreme4 HD667XZWF4 HD667XZWF4 
RAMHard DriveHard DriveOptical Drive
Corsair Vengeance LP Blue 2x8GB CL10 1600MHz Samsung 830 256GB SSD Seagate ST4000DM000 Pioneer BDR-206BDK 
Optical DriveCoolingOSMonitor
LG UH12NS29 Corsair H100i Windows 7 Ultimate x64 Dell U3011 
MonitorMonitorMonitorKeyboard
Dell 2007FP Dell 2007FP 32" 1920x1080 LED TV Logitech MX5500 Revolution 
PowerCase
Corsair HX750 Corsair Carbide 500R 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
Intel Core i7 3770k ASRock Z77 Extreme4 HD667XZWF4 HD667XZWF4 
RAMHard DriveHard DriveOptical Drive
Corsair Vengeance LP Blue 2x8GB CL10 1600MHz Samsung 830 256GB SSD Seagate ST4000DM000 Pioneer BDR-206BDK 
Optical DriveCoolingOSMonitor
LG UH12NS29 Corsair H100i Windows 7 Ultimate x64 Dell U3011 
MonitorMonitorMonitorKeyboard
Dell 2007FP Dell 2007FP 32" 1920x1080 LED TV Logitech MX5500 Revolution 
PowerCase
Corsair HX750 Corsair Carbide 500R 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › RelaxNG XML Schema Issue