You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Jose Luis Zabalza <jl...@gmail.com> on 2007/05/07 09:43:44 UTC

selector xpath descendant::* question

Hello everybody.

I am newbie so it is posible this will be a nosense question. Sorry.

I want to define a tree on XML file with references to his
nodes and xscheme validate. I am using SCMPrint xerces 2.7 C++ example to
*validate* xchema file and SAXPrint example to validate xml file.

This is the xml file example.

<!-- ============= nodes.xml ================ -->
<?xml version="1.0" encoding="iso-8859-1" ?>

<MAIN  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation='nodes.xsd'>

  <TREE>
    <NODE id="1">
      <NODE id="1_1">
        <NODE id="1_1_1"/>
	<NODE id="1_1_2"/>
      </NODE>

      <NODE id="1_2">
	<NODE id="1_2_1"/>
	<NODE id="1_2_2"/>
      </NODE>
    </NODE>
    <NODE id="2">
      <NODE id="2_1">
        <NODE id="2_1_1"/>
	<NODE id="2_1_2"/>
      </NODE>
      <NODE id="2_2">
	<NODE id="2_2_1"/>
	<NODE id="2_2_2"/>
      </NODE>
    </NODE>

<!-- This is a error example. Duplicate definition -->
    <NODE id="2_1_2"/>
  </TREE>

  <REFERENCES>
    <REFERENCE ref="1"/>
    <REFERENCE ref="1_1"/>
    <REFERENCE ref="1_2_1"/>

<!-- this is a error example. No defined reference. -->
    <REFERENCE ref="3"/>

  </REFERENCES>
</MAIN>
<!-- ============== EOF =================== -->



I think this the correct xscheme file.



<!-- ============= nodes.xsd ================ -->
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">


  <!-- =================================================== -->
  <xsd:complexType name="TypeNode">
    <xsd:sequence>
      <xsd:element name="NODE" type="TypeNode"
	minOccurs="0"
	maxOccurs='unbounded'/>

    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:string" use="required"/>
  </xsd:complexType>

  <!-- =================================================== -->
  <xsd:complexType name="TypeRefNode">
    <xsd:attribute name="ref" type="xsd:string" use="required"/>
  </xsd:complexType>


  <!-- =================================================== -->
  <xsd:element name="MAIN">
    <xsd:complexType>
      <xsd:sequence>
	<xsd:element name="TREE">
	  <xsd:complexType>
	    <xsd:sequence>
	      <xsd:element name="NODE"  type="TypeNode"
		minOccurs="0"
		maxOccurs='unbounded'/>
	    </xsd:sequence>
	  </xsd:complexType>
	</xsd:element>

	<xsd:element name="REFERENCES" >
	  <xsd:complexType>
	    <xsd:sequence>
	      <xsd:element name="REFERENCE"  type="TypeRefNode"
		minOccurs="0"
		maxOccurs='unbounded'/>
	    </xsd:sequence>
	  </xsd:complexType>
	</xsd:element>
      </xsd:sequence>
    </xsd:complexType>


    <xsd:key name="IdNodes">
      <xsd:selector xpath="TREE/descendant::*"/>
      <xsd:field xpath="@id"/>
    </xsd:key>

    <xsd:keyref name="IdRefNodes" refer="IdNodes">
      <xsd:selector xpath="REFERENCES/REFERENCE"/>
      <xsd:field xpath="@ref"/>
    </xsd:keyref>


  </xsd:element>
</xsd:schema>
<!-- ============== EOF =================== -->


If I execute :

==================================================
jlz@valinor:~/pro$ SCMPrint  nodes.xsd

Error at file /home/jlz/pro/nodes.xsd, line 50, char 49
  Message: XPath token not supported

Error at file /home/jlz/pro/nodes.xsd, line 54, char 51
  Message: Key reference declaration 'IdRefNodes' refers to unknown
key with name 'IdNodes'.
Did not parse a schema document cleanly so not printing Schema for
Schema XSModel information

==================================================

Xerces don't understand "descendant::*" XPath token. Why?

Is it correct?? How I can do this in other manner???

If I change

    <xsd:key name="IdNodes">
      <xsd:selector xpath="TREE/descendant::*"/>
      <xsd:field xpath="@id"/>
    </xsd:key>

by

    <xsd:key name="IdNodes">
      <xsd:selector xpath="TREE/*"/>
      <xsd:field xpath="@id"/>
    </xsd:key>


only the first children are identified. It's correct but it's not the
target.


Thank you very munch in avance.


-- 
José Luis Zabalza
jlz.3008 at gmail.com
Linux Counter 172551

Re: selector xpath descendant::* question

Posted by Alberto Massari <am...@datadirect.com>.
Hi Jose,

At 11.44 07/05/2007 +0200, Jose Luis Zabalza wrote:
>Thanks for your early response.
>
>2007/5/7, Alberto Massari <am...@datadirect.com>:
>>Hi Jose,
>>it's not that Xerces doesn't support
>>descendant::, it's that XMLSchema doesn't allow
>>that axis in the selector for identity constraints:
>
>Oops. Thanks for your explanation.
>
>>Try moving the identity constraint in the
>>definition for TREE and replace the selector with ".//NODE"
>
>But,... What will happens if REFERENCE was called NODE too.

In this case, keep the identity in the root node, it will still work.

Alberto


Re: selector xpath descendant::* question

Posted by Jose Luis Zabalza <jl...@gmail.com>.
Thanks for your early response.

2007/5/7, Alberto Massari <am...@datadirect.com>:
> Hi Jose,
> it's not that Xerces doesn't support
> descendant::, it's that XMLSchema doesn't allow
> that axis in the selector for identity constraints:

Oops. Thanks for your explanation.

> Try moving the identity constraint in the
> definition for TREE and replace the selector with ".//NODE"

But,... What will happens if REFERENCE was called NODE too.

<TREE>
...
 <NODE id="2">
 </TREE>
...
<REFERENCES>
...
    <NODE ref="2">
</REFERENCE>




-- 
José Luis Zabalza
jlz.3008 at gmail.com
Linux Counter 172551

Re: selector xpath descendant::* question

Posted by Alberto Massari <am...@datadirect.com>.
Hi Jose,
it's not that Xerces doesn't support 
descendant::, it's that XMLSchema doesn't allow 
that axis in the selector for identity constraints:

Schema Component Constraint: Selector Value OK
All of the following must be true:
1 The 
<file:///C:/users/alby/XML%20Schema%20Part%201%20%20Structures%20Second%20Edition.htm#selector>{selector} 
must be a valid XPath expression, as defined in 
<file:///C:/users/alby/XML%20Schema%20Part%201%20%20Structures%20Second%20Edition.htm#bib-xpath>[XPath].
2 One of the following must be true:
2.1 It must conform to the following extended BNF:
Selector XPath expressions
[1]   Selector   ::= 
<file:///C:/users/alby/XML%20Schema%20Part%201%20%20Structures%20Second%20Edition.htm#Path>Path 
( '|' 
<file:///C:/users/alby/XML%20Schema%20Part%201%20%20Structures%20Second%20Edition.htm#Path>Path 
)*
[2]   Path   ::=   ('.//')? 
<file:///C:/users/alby/XML%20Schema%20Part%201%20%20Structures%20Second%20Edition.htm#Step>Step 
( '/' 
<file:///C:/users/alby/XML%20Schema%20Part%201%20%20Structures%20Second%20Edition.htm#Step>Step 
)*
[3]   Step   ::=   '.' | 
<file:///C:/users/alby/XML%20Schema%20Part%201%20%20Structures%20Second%20Edition.htm#NameTest>NameTest
[4]   NameTest   ::= 
<http://www.w3.org/TR/REC-xml-names/#NT-QName>QName 
| '*' | <http://www.w3.org/TR/REC-xml-names/#NT-NCName>NCName ':' '*'
2.2 It must be an XPath expression involving the 
child axis whose abbreviated form is as given above.


Try moving the identity constraint in the 
definition for TREE and replace the selector with ".//NODE"

Alberto

At 09.43 07/05/2007 +0200, Jose Luis Zabalza wrote:
>Hello everybody.
>
>I am newbie so it is posible this will be a nosense question. Sorry.
>
>I want to define a tree on XML file with references to his
>nodes and xscheme validate. I am using SCMPrint xerces 2.7 C++ example to
>*validate* xchema file and SAXPrint example to validate xml file.
>
>This is the xml file example.
>
><!-- ============= nodes.xml ================ -->
><?xml version="1.0" encoding="iso-8859-1" ?>
>
><MAIN  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>       xsi:noNamespaceSchemaLocation='nodes.xsd'>
>
>  <TREE>
>    <NODE id="1">
>      <NODE id="1_1">
>        <NODE id="1_1_1"/>
>         <NODE id="1_1_2"/>
>      </NODE>
>
>      <NODE id="1_2">
>         <NODE id="1_2_1"/>
>         <NODE id="1_2_2"/>
>      </NODE>
>    </NODE>
>    <NODE id="2">
>      <NODE id="2_1">
>        <NODE id="2_1_1"/>
>         <NODE id="2_1_2"/>
>      </NODE>
>      <NODE id="2_2">
>         <NODE id="2_2_1"/>
>         <NODE id="2_2_2"/>
>      </NODE>
>    </NODE>
>
><!-- This is a error example. Duplicate definition -->
>    <NODE id="2_1_2"/>
>  </TREE>
>
>  <REFERENCES>
>    <REFERENCE ref="1"/>
>    <REFERENCE ref="1_1"/>
>    <REFERENCE ref="1_2_1"/>
>
><!-- this is a error example. No defined reference. -->
>    <REFERENCE ref="3"/>
>
>  </REFERENCES>
></MAIN>
><!-- ============== EOF =================== -->
>
>
>
>I think this the correct xscheme file.
>
>
>
><!-- ============= nodes.xsd ================ -->
><?xml version="1.0" encoding="ISO-8859-1" ?>
><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>
>
>  <!-- =================================================== -->
>  <xsd:complexType name="TypeNode">
>    <xsd:sequence>
>      <xsd:element name="NODE" type="TypeNode"
>         minOccurs="0"
>         maxOccurs='unbounded'/>
>
>    </xsd:sequence>
>    <xsd:attribute name="id" type="xsd:string" use="required"/>
>  </xsd:complexType>
>
>  <!-- =================================================== -->
>  <xsd:complexType name="TypeRefNode">
>    <xsd:attribute name="ref" type="xsd:string" use="required"/>
>  </xsd:complexType>
>
>
>  <!-- =================================================== -->
>  <xsd:element name="MAIN">
>    <xsd:complexType>
>      <xsd:sequence>
>         <xsd:element name="TREE">
>           <xsd:complexType>
>             <xsd:sequence>
>               <xsd:element name="NODE"  type="TypeNode"
>                 minOccurs="0"
>                 maxOccurs='unbounded'/>
>             </xsd:sequence>
>           </xsd:complexType>
>         </xsd:element>
>
>         <xsd:element name="REFERENCES" >
>           <xsd:complexType>
>             <xsd:sequence>
>               <xsd:element name="REFERENCE"  type="TypeRefNode"
>                 minOccurs="0"
>                 maxOccurs='unbounded'/>
>             </xsd:sequence>
>           </xsd:complexType>
>         </xsd:element>
>      </xsd:sequence>
>    </xsd:complexType>
>
>
>    <xsd:key name="IdNodes">
>      <xsd:selector xpath="TREE/descendant::*"/>
>      <xsd:field xpath="@id"/>
>    </xsd:key>
>
>    <xsd:keyref name="IdRefNodes" refer="IdNodes">
>      <xsd:selector xpath="REFERENCES/REFERENCE"/>
>      <xsd:field xpath="@ref"/>
>    </xsd:keyref>
>
>
>  </xsd:element>
></xsd:schema>
><!-- ============== EOF =================== -->
>
>
>If I execute :
>
>==================================================
>jlz@valinor:~/pro$ SCMPrint  nodes.xsd
>
>Error at file /home/jlz/pro/nodes.xsd, line 50, char 49
>  Message: XPath token not supported
>
>Error at file /home/jlz/pro/nodes.xsd, line 54, char 51
>  Message: Key reference declaration 'IdRefNodes' refers to unknown
>key with name 'IdNodes'.
>Did not parse a schema document cleanly so not printing Schema for
>Schema XSModel information
>
>==================================================
>
>Xerces don't understand "descendant::*" XPath token. Why?
>
>Is it correct?? How I can do this in other manner???
>
>If I change
>
>    <xsd:key name="IdNodes">
>      <xsd:selector xpath="TREE/descendant::*"/>
>      <xsd:field xpath="@id"/>
>    </xsd:key>
>
>by
>
>    <xsd:key name="IdNodes">
>      <xsd:selector xpath="TREE/*"/>
>      <xsd:field xpath="@id"/>
>    </xsd:key>
>
>
>only the first children are identified. It's correct but it's not the
>target.
>
>
>Thank you very munch in avance.
>
>
>--
>José Luis Zabalza
>jlz.3008 at gmail.com
>Linux Counter 172551