XPath to enforce document order

Discussion in 'XML' started by Phlip, Mar 17, 2009.

  1. Phlip

    Phlip Guest

    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/
     
    Phlip, Mar 17, 2009
    #1
    1. Advertising

  2. 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 !
     
    Philippe Poulard, Mar 17, 2009
    #2
    1. Advertising

  3. Phlip

    Phlip Guest

    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
     
    Phlip, Mar 17, 2009
    #3
  4. 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/
     
    Martin Honnen, Mar 17, 2009
    #4
  5. In article <N1Nvl.15843$>,
    Phlip <> 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.
     
    Richard Tobin, Mar 17, 2009
    #5
  6. In article <49bfc015$0$31344$-online.net>,
    Martin Honnen <> 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.
     
    Richard Tobin, Mar 17, 2009
    #6
  7. Phlip

    Phlip Guest

    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
     
    Phlip, Mar 17, 2009
    #7
  8. 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/
     
    Martin Honnen, Mar 18, 2009
    #8
  9. Phlip

    Phlip Guest

    > 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...
     
    Phlip, Mar 18, 2009
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mehdi
    Replies:
    2
    Views:
    408
    Mehdi
    Jan 29, 2005
  2. Niclas

    How to enforce registration ?

    Niclas, Mar 27, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    337
    Steve C. Orr [MVP, MCSD]
    Mar 27, 2006
  3. guava
    Replies:
    1
    Views:
    495
    Gordon Beaton
    Jul 11, 2003
  4. =?ISO-8859-1?Q?Sacha_Sch=E4r?=

    How to enforce execution order?

    =?ISO-8859-1?Q?Sacha_Sch=E4r?=, Jan 31, 2006, in forum: C++
    Replies:
    14
    Views:
    687
    Catalin Marinas
    Feb 2, 2006
  5. laredotornado
    Replies:
    30
    Views:
    3,564
    Mike Schilling
    Apr 26, 2010
Loading...

Share This Page