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 8874645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:46:26+00:00 2026-06-14T18:46:26+00:00

My XML (simplified) is like this: <Actions> <Action Id=1> </Action> <Action Id=2> <DoSomething> <ActionRef

  • 0

My XML (simplified) is like this:

<Actions>
    <Action Id="1">
    </Action>
    <Action Id="2">
        <DoSomething>
            <ActionRef ActionId="1" /> <!-- valid -->
        </DoSomething>
    </Action>
</Actions>

The ActionId attribute value references the Id attribute value of the Action element. I’ve already set up a foreign key constraint in the XSD, and it works correctly.

I want to prevent self-referencing values in the foreign field, like this:

<Actions>
    <Action Id="1">
    </Action>
    <Action Id="2">
        <DoSomething>
            <ActionRef ActionId="2" /> <!-- invalid -->
        </DoSomething>
    </Action>
</Actions>

Of course, this can easily be done within the application that processes the XML, and I’ll fall back on that if what I’m asking for isn’t possible, but I’d much rather have this done automatically by the validation process.

I tried adding [not(@ActionId = ../@Id)] to the foreign key selector XPath query, but that isn’t valid in that context (nor am I sure it’s correct either). Other than that, I have no idea what else to try, and it doesn’t look like many people on the internets even set up foreign key relationships in their XSDs, let alone prevent this kind of situation (I found nothing on this exact topic).

  • 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-06-14T18:46:28+00:00Added an answer on June 14, 2026 at 6:46 pm

    It cannot be done – the selector syntax for XSD constraints is very limited. Other alternatives may include Schematron, which should be reasonable to integrate assuming your runtime has access to an XSLT processor. The effort could pay off is you decide to add more validation rules separate from the code of the application that processes the XML.

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

Sidebar

Related Questions

I'm starting out with some XML that looks like this (simplified): <?xml version=1.0 encoding=UTF-8?>
I have a document which when simplified looks like this: <?xml version=1.0?> <document> <br/>
I have a XML (simplified) like this: <article> <title>My Article</title> <image src=someurl.jpg /> <image
Suppose I have this (outrageously) simplified XML schema: <xsd:complexType name=Person> <xsd:sequence> <xsd:element ref=FirstName/> <xsd:element
I have an XML like this - (simplified) <OrderBundle> <BundleDetail> <BundleId>12312</BundleId> <BundleUnit> <Idset> <PartNo>807651</PartNo>
I have an xml file that looks like this: <args> <sometag value=abc /> <anothertag
Having this (simplified) XML: <?xml version=1.0 encoding=UTF-8?> <kml> <Document> <Placemark> <name>Poly 1</name> <Polygon> <coordinates>
I have a DataGrid that looks like this (slightly simplified here): <asp:DataGrid ID=grdQuotas runat=server
I am serializing the cl_long2 type from OpenCL which is defined like this (simplified
I've defined a simple Xtext grammar which looks like this (simplified): grammar org.xtext.example.mydsl.MyDsl with

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.