Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4539032
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:53:26+00:00 2026-05-21T14:53:26+00:00

Ok I’ve been banging my head against this one so long, I think I’ve

  • 0

Ok I’ve been banging my head against this one so long, I think I’ve damaged my brain so much I forgot Shakespeare. It’s ok, I don’t use him that much. Here’s my problem.

I have a list of fruit at the top of an xml document. This is the “lookup table” so to speak.

I then build a menu system below. Each menu can have more menus, or a list of products. These products must correspond to the fruit at the top.

I have been able to confirm that the list of fruit is being populated, and can even get the keyref to validate one level of the menu. But I cannot get it to validate the whole menu tree. I have marked the locations I tried to run use keyref with <!-- KEY FAIL -->.

I’m using xmllint to validate. If I do any xpath’s with // in them, I get “Cannot compile”.

Here is the example xml:

<Snarf xmlns="" xsi:noNamespaceSchemaLocation="mySchema.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <Fruit name="apple" />
   <Fruit name="orange" />
   <Fruit name="watermelon" />

   <Blarg>
       <Menu name="Top Menu">
           <Menu name="Skillz">
               <Menu name="Juizy">
                   <Product>orange</Product>
                   <Product>watermelon</Product>
               </Menu>
               <Menu name="nutty">
                   <Product>orange</Product>
               </Menu>
           </Menu>
           <Menu name="Applz">
               <Product>apple</Product>
           </Menu>
       </Menu>
   </Blarg>
</Snarf>

Here is the xsd:

<xs:complexType name="productmenu">
<xs:choice minOccurs="1" maxOccurs="1">
    <xs:choice minOccurs="1" maxOccurs="unbounded">
        <xs:element name="Menu" type="productmenu">
            <!-- KEY FAIL -->
            <!-- <xs:keyref name="subMenuProductRef" refer="productNumber">
                <xs:selector xpath="Menu"/>
                <xs:field xpath="Product"/>
            </xs:keyref> -->
        </xs:element>
    </xs:choice>
    <xs:choice minOccurs="1" maxOccurs="unbounded">
        <xs:element name="Product" type="xs:integer"
            minOccurs="1" maxOccurs="unbounded"/>
    </xs:choice>
</xs:choice>
<xs:attribute name="name" type="xs:string" use="required" />
</xs:complexType>

<xs:element name="Snarf">
    <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">

<xs:element name="Fruit" maxOccurs="unbounded" minOccurs="1" type="string"/>

<xs:element name="Blarg" maxOccurs="unbounded" minOccurs="0">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Menu" type="productmenu"
                maxOccurs="unbounded" minOccurs="1">

                <!-- KEY FAIL -->
                <!-- <xs:keyref name="subMenuProductRef" refer="productNumber">
                    <xs:selector xpath="Menu"/>
                    <xs:field xpath="Product"/>
                </xs:keyref>-->
            </xs:element>
        </xs:sequence>
        <xs:attribute name="name" type="xs:string" use="required" />
    </xs:complexType>

    <!-- KEY FAIL -->
    <!-- <xs:keyref name="menuProductRef" refer="productNumber">
        <xs:selector xpath="Menu"/>
        <xs:field xpath="Product"/>
    </xs:keyref> -->
</xs:element>

        </xs:choice>
    </xs:complexType>

    <xs:key name="productNumber">
        <xs:selector xpath="./Product"/>
        <xs:field xpath="@num"/>
    </xs:key>
    <!-- KEY FAIL -->
    <!-- <xs:keyref name="menuProductRef" refer="productNumber">
        <xs:selector xpath="./Blarg/Menu"/>
        <xs:field xpath="Product"/>
    </xs:keyref> -->
</xs:element>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T14:53:27+00:00Added an answer on May 21, 2026 at 2:53 pm

    The selector is relative to its context, so with the keyRef inside Menu, the selector would the Product and the field within the selector is just .:

     <xs:element name="Menu" type="productmenu">
         <xs:keyref name="subMenuProductRef" refer="productNumber">
             <xs:selector xpath="Product"/>
             <xs:field xpath="."/>
         </xs:keyref>
     </xs:element>
    

    Your xs:key needs to be more like:

    <xs:key name="productNumber">
        <xs:selector xpath="./Fruit"/>
        <xs:field xpath="@name"/>
    </xs:key>
    

    but I’m guessing you just didn’t sanitize it for the example like the other parts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.