473,763 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1496
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:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns="http://dongfang.dk/testdata"
xmlns:input="ht tp://dongfang.dk/testdata"
version="1.0">

<xsl:template match="/">
<xsl:apply-templates
select="descend ant::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
16659
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
1285
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. I am trying to use the XPATH functions to pull the data for individual data elements. The order of the elements whose value I must find are not necessarily contiguous in the XML document. So walking the tree will not work.
3
4545
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 should result in a NodeSet". Of course, that (sort of) makes sense to me now (I suppose just an attribute couldn't be a nodeset, but how would I go
2
2882
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 - "xmlns="http://tempuri.org/nameOfRoot.xsd" I have no idea what its pointing to & what is tempuri.org? So when this tag is in my xml tag my xpath query never works. But when I delete it work fine.
9
2155
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 should work. Also the second nav.OuterXml appears to also be wrong to me. Can someone explain to me why this does not work? (This is an example from a program we have where xpath can be entered in two parts so we have to be able
5
7932
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
2812
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 type value to be the context of an XPath expression, by converting it to an XPath object -- either boolean, string or float. I do not see how this is possible, but I would like your thoughts on it.
0
1763
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
1062
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 would recommend the O'Reilly XSLT book, it has an excellent introduction to xpath in chapter 3.
0
9563
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9998
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.