Guru Advice Requested...

Discussion in 'XML' started by Skeets, Feb 17, 2006.

  1. Skeets

    Skeets Guest

    disclaimer - i'm an xml newb.

    my new project requires me to parse through an xml document and
    populate an html form with the values. this appears simple if the
    number of elements were to stay constant, however, they don't. i might
    have one <element> or three <element>.

    i'm using php and i'm planning on using PHP's DOM XML to parse through
    the document a (using foreach) to nab each value and store it into a
    variable and use those variables to display input into my forms. of
    course, i'll need to use foreach in order to create my form elements,
    too.

    my variables would be created as follows:

    $element1
    $elemtent2

    where the numeral is created as i loop through the values.

    does this sound reasonable? is their some kind of DOM XML magic that
    is designed to handle this case with ease?

    any help / guidance would be greatly appreciated.
    Skeets, Feb 17, 2006
    #1
    1. Advertising

  2. Skeets

    Guest

    you could use an array
    $elements = array()
    array_push ( $elements, $elementValue );
    numberOfElements = count( $elements )
    etc.

    Is this what you are asking? This should be simple enough.
    , Feb 18, 2006
    #2
    1. Advertising

  3. Skeets

    fedro Guest

    Skeets schrieb:

    > disclaimer - i'm an xml newb.
    >
    > my new project requires me to parse through an xml document and
    > populate an html form with the values. this appears simple if the
    > number of elements were to stay constant, however, they don't. i might
    > have one <element> or three <element>.
    >
    > i'm using php and i'm planning on using PHP's DOM XML to parse through
    > the document a (using foreach) to nab each value and store it into a
    > variable and use those variables to display input into my forms. of
    > course, i'll need to use foreach in order to create my form elements,
    > too.
    >
    > my variables would be created as follows:
    >
    > $element1
    > $elemtent2
    >
    > where the numeral is created as i loop through the values.
    >
    > does this sound reasonable? is their some kind of DOM XML magic that
    > is designed to handle this case with ease?
    >
    > any help / guidance would be greatly appreciated.


    i had nearly the same problem and solved it as follows:

    first i load my XML-Data in an DOMDocument. Afterwards i label every
    element with a numbered "name" tag using XPath-expression "//*".

    that's it:

    $xml = DOMDocument::load($_GET["xml"]);
    $XPath = new DOMXPath($xml);
    $r = $XPath->query("//*");
    for ($i=0;$i<$r->length;$i++) {
    $r->item($i)->setAttribute("name", $i);
    }

    For creating the form i recommend XSL.

    Cheers,
    Dominik

    By sending the form you can recognize the data in the fields by that
    name.
    fedro, Feb 18, 2006
    #3
  4. Skeets wrote:

    > i might
    > have one <element> or three <element>.


    That is not a problem at all as there are methods like
    $domDocument->getElementsByTagName('element')
    or
    $someElement->getElementsByTagName('element')
    to give you a node list of those element nodes for further processing.
    And there is the possibility to use XPath for more complicated selections.

    > my variables would be created as follows:
    >
    > $element1
    > $elemtent2
    >
    > where the numeral is created as i loop through the values.


    Does not sound like an XML problem then, as said for the XML elements
    you have a node list to process, other data structures you want to fill
    then are not XML related and as already suggested PHP has arrays to
    allow you to store data e.g.
    $data = array();
    $data[] = ...;
    $data[] = ...;
    will increase the length of the array with each assignment.



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Feb 19, 2006
    #4
    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. Brian
    Replies:
    2
    Views:
    2,131
    BMukes
    May 28, 2004
  2. David Straley

    Advice on architecture requested

    David Straley, Jul 23, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    102
    David Straley
    Jul 23, 2003
  3. middletree

    programming advice requested

    middletree, Jan 2, 2004, in forum: ASP General
    Replies:
    2
    Views:
    140
    middletree
    Jan 3, 2004
  4. Alex Martelli

    performance and style advice requested

    Alex Martelli, Sep 14, 2003, in forum: Ruby
    Replies:
    12
    Views:
    184
    Alex Martelli
    Sep 16, 2003
  5. Sean Hussey

    Ruby - Newbie to Guru - Advice?

    Sean Hussey, Nov 10, 2005, in forum: Ruby
    Replies:
    7
    Views:
    96
    Gregory Brown
    Nov 14, 2005
Loading...

Share This Page