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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:40:24+00:00 2026-05-21T22:40:24+00:00

I have an XML value and an XPath query like this: XML: <Firms> <Firm

  • 0

I have an XML value and an XPath query like this:

XML:

<Firms>
    <Firm id="1" select="1" update="1" insert="1" delete="1">
        <Backoffice select="1" update="1" insert="1" delete="1">
            <Transaction select="1" update="1" insert="1" delete="0">
                <DatePeriod startDate="20110101" endDate="20110505" select="1" update="0" insert="0" delete="0"/>
                <DatePeriod startDate="20100101" endDate="20110101" select="0" update="0" insert="0" delete="0"/>
            </Transaction>
        </Backoffice>
    </Firm>
</Firms>

XPath:

./Firms/Firm[@id="1"]/Backoffice/Transaction/DatePeriod

I want to get values of the longest prefix of XPath, contained in XML.

In my example the values would be:

<DatePeriod startDate="20110101" endDate="20110505" select="1" update="0" insert="0" delete="0"/>
<DatePeriod startDate="20100101" endDate="20110101" select="0" update="0" insert="0" delete="0"/>

If we change the XPath to

./Firms/Firm[@id="1"]/Backoffice/Client/Account

the expected result should be

<Firms>
    <Firm id="1" select="1" update="1" insert="1" delete="1">
        <Backoffice select="1" update="1" insert="1" delete="0"/>
    </Firm>
</Firms>

Let me explain what is going on. The XML describes user’s privileges, the XPath describes the security context (the securable object). First we try to find out if there is an exact rule about the object (./Firms/Firm[@id="1"]/Backoffice/Client/Account) and check the expected rights (select, insert or update). If we don’t find it we go to the parent level (./Firms/Firm[@id="1"]/Backoffice/Client) and try to apply the uplevel rules (if they exist). And so on. Finally we find the existing level (./Firms/Firm[@id="1"]/Backoffice) and see that the parent rule gives us the rights to select, update, but not to delete.

Is there a way to implement this logic via XPath (for SQL Server 2008)?

  • 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-21T22:40:24+00:00Added an answer on May 21, 2026 at 10:40 pm

    The only way that I can think of doing this is by programmatically try-and-fail:

    1. you build your most specific XPath expression (./Firms/Firm[@id="1"]/Backoffice/Client/Account); let’s call it X

    2. you use X to find matching nodes; if you find any, then you’ve finished, otherwise you go to step 3.

    3. if you can generalize X by removing the last part of it, then do it and go to step 2; otherwise you can’t find any match in your XML, and you probably want to raise an error.

    I can’t help on how to do this with SQL Server 2008, sorry.

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

Sidebar

Related Questions

I have XML that looks like this: <Parameter Name=parameter name Value=parameter value /> which
I have a XML file like this: <Document> <Tests> <Test> <Name>A</Name> <Value>1</Value> </Test> <Test>
Greetings! I have some XML like this: <Root> <MainSection> <SomeNode>Some Node Value</SomeNode> <SomeOtherNode>Some Other
I have an XML like this <root> <el id=1 value=3/> <el id=2 value=3/> <el
For example i have this xml. I need to get value of parameter val
I have a very simple XML datasource structured like this: <datasource> <row> <column>Some text
Greetings! I have an XML value that I'd like to use as a boolean
I have a big xml document that looks like this: <Node name=foo> <Node name=16764764625>
Say I have an XML file which looks like this: <?xml version=1.0 encoding=UTF-8?> <Project
Lets say I have an xml structure like this: <s> <a> <b id=myid>value1</b> <c

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.