Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XPath to enforce document order

Reply
Thread Tools

XPath to enforce document order

 
 
Phlip
Guest
Posts: n/a
 
      03-17-2009
XMLers:

Here's my XPath:

//form[
./descendant::fieldset[
./descendant::legend and
./descendant::li[
./descendant::label and
./descendant::input ]
]
]

Its purpose is unit tests to assert that HTML has certain elements and
attributes (not shown).

I want it to fail if the <li> appears above the <legend>, in document order. Or
if the <label> appears below the <input>. Any ideas?

libxml2, 2.6.32.dfsg-4ubuntu1.1, BTW... Tx!

--
Phlip
http://www.zeroplayer.com/
 
Reply With Quote
 
 
 
 
Philippe Poulard
Guest
Posts: n/a
 
      03-17-2009
Phlip a écrit :
> XMLers:
>
> Here's my XPath:
>
> //form[
> ./descendant::fieldset[
> ./descendant::legend and
> ./descendant::li[
> ./descendant::label and
> ./descendant::input ]
> ]
> ]
>
> Its purpose is unit tests to assert that HTML has certain elements and
> attributes (not shown).
>
> I want it to fail if the <li> appears above the <legend>, in document
> order. Or if the <label> appears below the <input>. Any ideas?


Hi,

This is a job for WUnit :
http://reflex.gforge.inria.fr/wunit.html
http://reflex.gforge.inria.fr/wunit-quick-start.html

>
> libxml2, 2.6.32.dfsg-4ubuntu1.1, BTW... Tx!
>



--
Cordialement,

///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
-----------------------------
http://reflex.gforge.inria.fr/
Have the RefleX !
 
Reply With Quote
 
 
 
 
Phlip
Guest
Posts: n/a
 
      03-17-2009
Philippe Poulard wrote:
> Phlip a écrit :
>> XMLers:
>>
>> Here's my XPath:
>>
>> //form[
>> ./descendant::fieldset[
>> ./descendant::legend and
>> ./descendant::li[
>> ./descendant::label and
>> ./descendant::input ]
>> ]
>> ]
>>
>> Its purpose is unit tests to assert that HTML has certain elements and
>> attributes (not shown).
>>
>> I want it to fail if the <li> appears above the <legend>, in document
>> order. Or if the <label> appears below the <input>. Any ideas?


> This is a job for WUnit :


Please don't make my question look answered in the forum. I'm not the
user-programmer testing a page, I'm the vendor-programmer writing an assertion,
so I actually need an answer.

And Ruby on Rails hardly needs a new system to mock the web server and browser.
My assertion does not require the incredible verbosity of XSL. Good luck getting
XSL, or Java, to look like this:

assert_xhtml do
h2 'ACH Sales'
select! :size => SaleController::LIST_SIZE do
option names[1]
option names[0]
end
end

We just write the names and values of our target HTML elements into the block.

--
Phlip
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      03-17-2009
Phlip wrote:

> Here's my XPath:
>
> //form[
> ./descendant::fieldset[
> ./descendant::legend and
> ./descendant::li[
> ./descendant::label and
> ./descendant::input ]
> ]
> ]
>
> Its purpose is unit tests to assert that HTML has certain elements and
> attributes (not shown).
>
> I want it to fail if the <li> appears above the <legend>, in document
> order. Or if the <label> appears below the <input>. Any ideas?


Maybe
//form[
descendant::fieldset[
descendant::legend[
following-sibling::*[
descendant-or-self::li[
descendant::label[
following-sibling::*[
descendant-or-self::input
]
]
]
]
]
]




--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      03-17-2009
In article <N1Nvl.15843$(E-Mail Removed)>,
Phlip <(E-Mail Removed)> wrote:

>Please don't make my question look answered in the forum.


What does this mean? How does a question "look answered"? Are you
suggesting that people shouldn't reply to Usenet postings unless they
are giving the exact answer you want?

-- Richard
--
Please remember to mention me / in tapes you leave behind.
 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      03-17-2009
In article <49bfc015$0$31344$(E-Mail Removed)-online.net>,
Martin Honnen <(E-Mail Removed)> wrote:

>> I want it to fail if the <li> appears above the <legend>, in document
>> order. Or if the <label> appears below the <input>. Any ideas?


>Maybe
> //form[
> descendant::fieldset[
> descendant::legend[
> following-sibling::*[
> descendant-or-self::li[
> descendant::label[
> following-sibling::*[
> descendant-or-self::input
> ]
> ]
> ]
> ]
> ]
> ]


Not that this just checks for the existence of elements in the right
order. It doesn't prevent there *also* being an <li> before the
<legend>.

-- Richard
--
Please remember to mention me / in tapes you leave behind.
 
Reply With Quote
 
Phlip
Guest
Posts: n/a
 
      03-17-2009
Richard Tobin wrote:

> What does this mean? How does a question "look answered"? Are you
> suggesting that people shouldn't reply to Usenet postings unless they
> are giving the exact answer you want?


My bad - I'm familiar with higher volume forums, where I (for one) tend to skip
the questions with a Re tag indicate someone answered. This, in turn, reduces
the quality of answers if the first answer was spurious.

I will try Martin's suggestion; ignoring the other <li> tag is okay if the
terminal paths typically have attributes (not shown) that pin them down.

The goal is if an assertion puts <select><option> content in collating order,
for example, they must run in that order in the View!

--
Phlip
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      03-18-2009
Phlip wrote:

> path = "//fieldset[
> descendant::legend[
> following-sibling::*[
> descendant-or-self::li[
> descendant::label[
> following-sibling::*[
> descendant-or-self::br[
> following-sibling::*[
> descendant-or-self::input ] ] ] ] ] ] ] ]"
>
> Problem: Here's the sample input:
>
> <fieldset>
> <legend>Personal Information</legend>
> <ol>
> <li id="control_user_first_name">
> <label for="user_first_name">First name</label>
> <input type="text" name="user[first_name]" id="user_first_name" />
> <br/>
> </li>
> </ol>
> </fieldset>
>
> Notice the <br/> is below the <input>, not above it.
>
> Ironically, I can move other elements around and successfully fail the
> query.
>
> Bug in libxml2? Pilot error? Gap in the language specification?


When I evaluate your XPath expression against the sample XML you posted
then it returns an empty node-set. Tested with the XPath tool in jEdit's
XML and XSLT/XPath plugin which is based on Xalan Java.

I don't see why it should find a node as the 'br' element has no
following-sibling::* element at all.

Thus if libxml2 with that expression and XML input returns a non-empty
node-set then I think it has a bug.



--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
Phlip
Guest
Posts: n/a
 
      03-18-2009
> Thus if libxml2 with that expression and XML input returns a non-empty
> node-set then I think it has a bug.


Gee - I usually love to watch the results when _other_ people push the
envelop... (-:

Tx for the manual test!

I will see if my intermediate library (Nokogiri) is calling libxml2's HTML
parser, and will upgrade to XML and see if that fixes things...
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Way to sort / enforce order for Map.entrySet? laredotornado Java 30 04-26-2010 07:14 PM
How to enforce execution order? =?ISO-8859-1?Q?Sacha_Sch=E4r?= C++ 14 02-02-2006 08:41 PM
"Memory leak" in javax.xml.xpath.XPath Marvin_123456 Java 4 07-29-2005 03:49 PM
XPath that does not include other XPath Anna XML 0 07-31-2003 07:55 AM
Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal? Alastair Cameron XML 1 07-08-2003 07:24 PM



Advertisments