Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Getting the parent when the child doesn't exist

From: Pavel Minaev <int19h@-----.--->
To: NULL
Date: 3/3/2009 1:32:00 PM
On Mar 3, 9:50=A0am, "Greg Collins" <gcollins_at_msn_dot_com> wrote:
> I'm posting this to both the XSL and C# newsgroups because it spans both.
>
> I have an XPath passed to me that starts at the root node and goes down t=
o a
> table row node. From this XPath I was grabbing the table node by appendin=
g a
> "/.." to the end of the XPath.
>
> While this technique works great when the row exists, if the row does not
> exist, I can no longer identify the table node.
>
> In code, one might say, well just rip off everything past the last slash
> character. This won't work because I cannot guarantee that a filter is no=
t
> being used. And there might be nested filters and "[" and "]" characters
> used in the filter as values.
>
> So what I need to find is a way to extrapolate the parent XPath from that
> which is passed in, but accounting for potential nested filters and [ ]
> characters used as filter values.

As Jeroen says, there is no truly generic solution, as an XPath
expression needs not explicitly mention the parent of the child at
all.

If you can guarantee that the expression truly has the form /foo/bar/
baz (i.e. only ever uses child:: axis), and optional filters on every
step, then you can of course just parse that expression and drop the
final part of the path. You might even be able to handle that sort of
parsing with regex, as .NET ones are powerful enough to handle nested
square brackets - for an example, see http://www.m-8.dk/resources/RegEx-nes=
ted-constructions.aspx.
Even so, it may be very tricky to get right, and quite likely it is
better to just write a proper XPath parser (only handling the
simplified grammar as described earlier - this will also ensure that,
if something wrong is passed to you, you don't silently parse it
wrong). XPath grammar is fairly simple and unambiguous, so you
shouldn't have a problem a parser generator - COCO/R is neat and very
small, ANTLR is another good and very powerful one, and there are
plenty others.


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent