473,396 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

xPath question

Hi everyone,

I have a problem that I've been trying to figure out for a while but I
just can't seem to get it right. I have the following XML fragment:

<Page ID="x1" Schema="Folder">
-<Page ID="x10" Schema="Common">
--<Page ID="x100" Schema="Common" />
--<Page ID="x200" Schema="Common" />
--<Page ID="x300" Schema="Common" />
---<Page ID="x301" Schema="Folder">
----<Page ID="x3010" Schema="Link" />
----<Page ID="x3011" Schema="Link" />
----<Page ID="x3012" Schema="Link" />
----<Page ID="x3013" Schema="Link" />
----<Page ID="x3014" Schema="Link" />
----<Page ID="x3015" Schema="Link" />
----<Page ID="x3016" Schema="Link" />
---</Page>
---<Page ID="x302" Schema="Common">
----<Page ID="x3020" Schema="Common"/>
---</Page>
---<Page ID="x303" Schema="Common">
----<Page ID="x3030" Schema="Link" />
----<Page ID="x3031" Schema="Link" />
---</Page>
---<Page ID="x304" Schema="List">
----<Page ID="x3040" Schema="Folder" />
---</Page>
---<Page ID="x305" Schema="Common" />
--<Page ID="x400" Schema="Common" />
--<Page ID="x500" Schema="Common" />
--<Page ID="x600" Schema="Common" />
-</Page>
</Page>

I'm trying to retrieve all of the Pages below x300 (not including x300)
except those where the Schema value is 'Folder' or the parent page's
Schema value is 'Folder' (specifically these pages should be excluded:
ID = x301 [and children x3010 - x3016] and x3040). I've been able to
successfully remove x301 and children using this xPath query:

//*[@ID='x300']/Page[@Schema != 'Folder']

However, when I modify the query to:

//*[@ID='x300']/descendant-or-self::Page[@Schema != 'Folder']

The resultset breaks completely with all of the 3 nodes getting
promoted to level 2.

I've also tried to use the ancestor-or-self method but this also does
not return the results I'm attempting to retrieve - I actually get no
results. I believe that this occurs because there is a Page with a
Schema value of 'Folder' below my initial criteria and that the
sub-selection occurs after the attribute restriction is applied.

I appreciate any help. Thank you.

-Christian

Jan 19 '06 #1
4 1478
cgaden wrote:
Hi everyone, I'm trying to retrieve all of the Pages below x300 (not including x300)
Below, is that:

- a smaller number than

- a descendant of

- apperaring later in the docuemnt than

???
except those where the Schema value is 'Folder' or the parent page's
Schema value is 'Folder' (specifically these pages should be excluded:
ID = x301 [and children x3010 - x3016] and x3040). I've been able to
successfully remove x301 and children using this xPath query:

//*[@ID='x300']/Page[@Schema != 'Folder'] The resultset breaks completely with all of the 3 nodes getting
promoted to level 2.
Level ;) ? XPath node sets are flat (I presume you know) ;)
I've also tried to use the ancestor-or-self method but this also does
not return the results I'm attempting to retrieve - I actually get no
results. I believe that this occurs because there is a Page with a
Schema value of 'Folder' below my initial criteria and that the
sub-selection occurs after the attribute restriction is applied.

I appreciate any help. Thank you.

-Christian

The select exp in this stylesheet is my bet (the rest of it is just a
demonstrator application, don't worry if you don't know XSLT):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://dongfang.dk/testdata"
xmlns:input="http://dongfang.dk/testdata"
version="1.0">

<xsl:template match="/">
<xsl:apply-templates
select="descendant::Page[@ID='x300']/following::Page[not(@Schema =
'Folder' or parent::*/@Schema = 'Folder')]"/>
</xsl:template>

<xsl:template match="Page">
Got page w ID: <xsl:value-of select="@ID"/>
</xsl:template>

<xsl:template match="*">
Whoops, the expression selected something that was not a page. Back
to the drawing board you go.
</xsl:template>

</xsl:stylesheet>
Spews out
<?xml version="1.0"?>

Got page w ID: x302
Got page w ID: x3020
Got page w ID: x303
Got page w ID: x3030
Got page w ID: x3031
Got page w ID: x304
Got page w ID: x305
Got page w ID: x400
Got page w ID: x500
Got page w ID: x600
when applied 2 yr doc.

Soren
Jan 20 '06 #2
Soren Kuula wrote:
cgaden wrote:
Hi everyone,


Did it work ;) ?

Soren
Jan 21 '06 #3
Hi Soren,

Unfortunately it did not work as I had hoped. In normal circumstances I
would remove the nodes using my XSLT stylesheet (in fact that's one of
the tasks my stylesheet does now) but I'm working within the framework
of a black-box application and in order to improve that application's
performance I'm attempting to remove the excess nodes prior to
processing the data with the stylesheet.

-Christian

Jan 23 '06 #4
Hi Everyone,

Thank you all for the assistance. I just realized that my sample XML
from my original post actually contains an error. I apologize to the
group for my mistake.

The error was that node ID = x300 was supposed to be the
parent/grandparent for all other nodes IDed x30[n[n]].

The XML that I'm trying to parse is actually the following:

<Page ID="x1" Schema="Folder">
-<Page ID="x10" Schema="Common">
--<Page ID="x100" Schema="Common" />
--<Page ID="x200" Schema="Common" />
--<Page ID="x300" Schema="Common">
---<Page ID="x301" Schema="Folder">
----<Page ID="x3010" Schema="Link" />
----<Page ID="x3011" Schema="Link" />
----<Page ID="x3012" Schema="Link" />
----<Page ID="x3013" Schema="Link" />
----<Page ID="x3014" Schema="Link" />
----<Page ID="x3015" Schema="Link" />
----<Page ID="x3016" Schema="Link" />
---</Page>
---<Page ID="x302" Schema="Common">
----<Page ID="x3020" Schema="Common"/>
---</Page>
---<Page ID="x303" Schema="Common">
----<Page ID="x3030" Schema="Link" />
----<Page ID="x3031" Schema="Link" />
---</Page>
---<Page ID="x304" Schema="List">
----<Page ID="x3040" Schema="Folder" />
---</Page>
---<Page ID="x305" Schema="Common" />
--</Page>
--<Page ID="x400" Schema="Common" />
--<Page ID="x500" Schema="Common" />
--<Page ID="x600" Schema="Common" />
-</Page>
</Page>

The exact result I'm trying to retrieve is this (all of the
child/grandchild nodes of x300 that are not Schema = 'Folder' or
children of pages where Schema = 'Folder'):

<Page ID="x302" Schema="Common">
-<Page ID="x3020" Schema="Common"/>
</Page>
<Page ID="x303" Schema="Common">
-<Page ID="x3030" Schema="Link" />
-<Page ID="x3031" Schema="Link" />
</Page>
<Page ID="x304" Schema="List" />
<Page ID="x305" Schema="Common" />

Again, thank you all for your input.

-Christian

Jan 24 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Sebastian Petzelberger | last post by:
Hi group, please give me an example of a xpath with regex or better a link with examples. Thanks in advance, Sebastian
0
by: Bart | last post by:
Hello, I am real new to using LIBXML and have a question about XPATH evaluations. The question may show a real ignorance of the LIBXML structure, don't so assume I know what I am talking about....
3
by: Kathy Burke | last post by:
Hi again, I'm using the following xpath (works in visualizer) with a SelectSingleNode("xpath") statement. //Station/(WI])]/@order Problem is I get an error "expression passed to this method...
2
by: ree32 | last post by:
When I import an xml document in Visual studio and Genereate as schema from it, and create a dataset from it, it adds this line into to the root element of my xml file -...
9
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they...
5
by: Gnic | last post by:
Hi , I have an XmlDocument instance, I want to find a node in the xml, but I don't know it's path until runtime, for example <aaa> <bbb name="x"/> <aaa attr="y"> <ccc>sometext</ccc> </aaa>
7
by: Tim Hallwyl | last post by:
Hi, there! As I understand the XPaht recommendation, the context node is a node; not a node-list, not XPath object -- but a single node. Now, the WS-BPEL 2.0 specification allows an XML simple...
0
by: pompair | last post by:
Hello, I'm making a quiz game for fun. I have an xml file like this: <?xml version="1.0" encoding="utf-8" ?> <results> <index>99</index> <answers>11</answers> <questions> <question id="1">
0
by: John Krukoff | last post by:
On Wed, 2008-09-03 at 13:36 -0700, bruce wrote: Well, you could just do the test (and the count!) in the xpath expression: count( //tr/td ) It sounds like you're not familiar with xpath? I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.