Skip to main content
1-Visitor
September 15, 2010
Question

Element End Flag

  • September 15, 2010
  • 4 replies
  • 972 views

Is there an ACL command to determine the end of an element ?

Whilst reading an XML file from top to bottom I am setting a flag when I come across a table for example:

if( oid_name(this_o) == "table" ){
in_table=1;
}

How do I turn the flag off when I get to the end of the table element?

Is there an oid command for this ?

Regards,

Andy

    4 replies

    1-Visitor
    September 15, 2010
    Can you show more of your code, so we can see exactly how you're
    traversing the document?  Depending on how you're doing this, you'll
    probably "pass by" the table again on your way out of it, so you can
    reset your flag.

    Remember, the document is modeled like a tree, with each element
    forming a branch.  You pass through the table "node" to enter its
    branch and you'll pass through that node again on the way back out.

    -Brandon 🙂


    On Wed, Sep 15, 2010 at 9:55 AM, Andy Leslie
    <info@structuredinformation.co.uk> wrote:
    > Is there an ACL command to determine the end of an element ?
    >
    > Whilst reading an XML file from top to bottom I am setting a flag when I
    > come across a table for example:
    >
    > if( oid_name(this_o) == "table" ){
    >   in_table=1;
    > }
    >
    > How do I turn the flag off when I get to the end of the table element?
    >
    > Is there an oid command for this ?
    >
    > Regards,
    >
    > Andy
    >
    > ----------
    aleslie1-VisitorAuthor
    1-Visitor
    September 15, 2010

    I'm simply using the following for loop from the top :

    for( ; oid_valid( this_o )&&!dm_end; this_o = oid_forward( this_o ) ) {

    if( oid_name(this_o) == "table" ){
    in_table=1;
    }

    etc..

    }

    1-Visitor
    September 15, 2010
    I don't know what you are doing or why or what other constraints there might
    be (that's my -- I'm about to tell you to do something totally different
    please don't take offense because maybe I'm wrong and you are right plus
    even if your scenario is most efficiently and extensibly and maintainably
    solved in a linear way someone who has not thought it through might benefit
    15-Moonstone
    September 15, 2010
    For example, say that you want to process all paragraph elements only if
    they are located within a table.

    Then you ask (I'll do it almost declaratively here rather than
    imperatively as you're doing) to create an array with all paragraph
    elements that verify this condition



    $c = xpath_nodeset($a, "para[ancestor::table]") # get all para elements
    that have a table ancestor



    This will return in $c the number of paragraph elements matching the
    condition (that is, that are contained in a table) and the array of all
    paragraph elements in $a; then you navigate $a and do what you want on
    the elements



    for ( $i in $a )

    {

    # do something on $a[$i]

    }



    Please explain your functional requirement so that it would be easier to
    advise on the best idiom to use



    Alessio