getting the right XML tag in the parse.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • news@celticbear.com

    getting the right XML tag in the parse.

    I'm trying to parse an XML formatted post reply, and I can't figure
    out how to get the value of the right tag.
    The XML is formatted like this:

    <A>
    <foo>val1</foo>
    </A>
    <B>
    <foo>val2</foo>
    </B>
    <BAR>
    val3
    </BAR>

    I need the value of A's "foo", not B's "foo". But from what I can find
    I can only get the value of the lowest nested tag in a nest. i.e.:
    "foo" or "BAR". Not specifically A or B's "foo".
    Below is the script I'm using. In this case "TOTALCHARG ES" is the
    "foo" I'm looking for, but I need it to specifically get A's and not
    B's.
    If someone can point me to where I can find out how, I'd appreciate
    it!
    -Liam

    //Defines startElement function
    function startElement($x ml_parser, $element_name, $element_attrs) {
    global $printout, $tag, $output1;

    switch($element _name) {
    case "TOTALCHARG ES":
    $printout = true;
    $tag = "TOTALCHARG ES";
    break;
    }
    }

    //Defines endElement function
    function endElement($xml _parser, $element_name) {
    global $printout, $tag, $output1;

    switch($element _name) {
    case "TOTALCHARG ES":
    $printout = false;
    $tag = "";
    break;
    }
    }

    //Defines characterData function
    function characterData($ xml_parser, $fp) {
    global $printout, $tag, $output1;

    if (($tag=="TOTALC HARGES") && ($printout==tru e)) {
    $output1 = $fp;
    //echo $output;
    }
    return $output1;
    }
  • Michael Fesser

    #2
    Re: getting the right XML tag in the parse.

    ..oO(news@celti cbear.com)
    >I'm trying to parse an XML formatted post reply, and I can't figure
    >out how to get the value of the right tag.
    >The XML is formatted like this:
    >
    ><A>
    <foo>val1</foo>
    ></A>
    ><B>
    <foo>val2</foo>
    ></B>
    ><BAR>
    val3
    ></BAR>
    If this is the entire document, then it's not well-formed XML, because
    there's no root element.
    >I need the value of A's "foo", not B's "foo". But from what I can find
    >I can only get the value of the lowest nested tag in a nest. i.e.:
    >"foo" or "BAR". Not specifically A or B's "foo".
    Of course you can access every element and every attribute in the tree.
    Just use the right tools.
    >Below is the script I'm using. In this case "TOTALCHARG ES" is the
    >"foo" I'm looking for, but I need it to specifically get A's and not
    >B's.
    >If someone can point me to where I can find out how, I'd appreciate
    >it!
    >[...]
    You don't have to write your own parser. Use the SimpleXML extension
    with some XPath expressions to get all the nodes you want.

    Micha

    Comment

    • news@celticbear.com

      #3
      Re: getting the right XML tag in the parse.

      On Jul 18, 10:51 am, Michael Fesser <neti...@gmx.de wrote:
      .oO(n...@celtic bear.com)
      >
      I'm trying to parse an XML formatted post reply, and I can't figure
      out how to get the value of the right tag.
      The XML is formatted like this:
      >
      <A>
        <foo>val1</foo>
      </A>
      <B>
        <foo>val2</foo>
      </B>
      <BAR>
        val3
      </BAR>
      >
      If this is the entire document, then it's not well-formed XML, because
      there's no root element.
      LOL of course that's not the whole document, not the document at all.
      It's an example specifically the nesting and tag labeling that I'm
      talking about--for the sake of example.
      I need the value of A's "foo", not B's "foo". But from what I can find
      I can only get the value of the lowest nested tag in a nest. i.e.:
      "foo" or "BAR". Not specifically A or B's "foo".
      >
      Of course you can access every element and every attribute in the tree.
      Just use the right tools.
      I knew it was possible...I was asking for advice HOW. WHAT are the
      right tools?
      Below is the script I'm using. In this case "TOTALCHARG ES" is the
      "foo" I'm looking for, but I need it to specifically get A's and not
      B's.
      If someone can point me to where I can find out how, I'd appreciate
      it!
      [...]
      >
      You don't have to write your own parser. Use the SimpleXML extension
      with some XPath expressions to get all the nodes you want.
      In my opinion, writing several lines of script in standard PHP is a
      LOT easier than installing an extension (and learning how to install
      an extension as I've never done that before.)
      IF that's the ONLY way to do what I need to do, then so be it. I'll
      figure out how to install SimpleXML and how to use XPath.
      But if there's a way to do it by simply modifying the regular PHP
      getElements and characterData, etc, that's the best way for me to go.

      Comment

      • Michael Fesser

        #4
        Re: getting the right XML tag in the parse.

        ..oO(news@celti cbear.com)
        >On Jul 18, 10:51 am, Michael Fesser <neti...@gmx.de wrote:
        >
        >I need the value of A's "foo", not B's "foo". But from what I can find
        >I can only get the value of the lowest nested tag in a nest. i.e.:
        >"foo" or "BAR". Not specifically A or B's "foo".
        >>
        >Of course you can access every element and every attribute in the tree.
        >Just use the right tools.
        >
        >I knew it was possible...I was asking for advice HOW. WHAT are the
        >right tools?
        >
        >Below is the script I'm using. In this case "TOTALCHARG ES" is the
        >"foo" I'm looking for, but I need it to specifically get A's and not
        >B's.
        >If someone can point me to where I can find out how, I'd appreciate
        >it!
        >[...]
        >>
        >You don't have to write your own parser. Use the SimpleXML extension
        >with some XPath expressions to get all the nodes you want.
        >
        >In my opinion, writing several lines of script in standard PHP is a
        >LOT easier than installing an extension (and learning how to install
        >an extension as I've never done that before.)
        Why re-invent the wheel? SimpleXML (and the more powerful DOM) are
        standard extensions and should be installed and enabled by default in
        every recent PHP. We are talking about PHP 5, right?
        >IF that's the ONLY way to do what I need to do, then so be it. I'll
        >figure out how to install SimpleXML and how to use XPath.
        Check phpinfo() to see if SimpleXML is already there (it should be).
        Then check the manual for some examples on how to use it with XPath
        syntax to fetch arbitrary elements from an XML tree. Can't get any
        easier.

        Micha

        Comment

        • news@celticbear.com

          #5
          Re: getting the right XML tag in the parse.

          On Jul 18, 2:29 pm, Michael Fesser <neti...@gmx.de wrote:
          .oO(n...@celtic bear.com)
          >
          >
          >
          On Jul 18, 10:51 am, Michael Fesser <neti...@gmx.de wrote:
          >
          I need the value of A's "foo", not B's "foo". But from what I can find
          I can only get the value of the lowest nested tag in a nest. i.e.:
          "foo" or "BAR". Not specifically A or B's "foo".
          >
          Of course you can access every element and every attribute in the tree..
          Just use the right tools.
          >
          I knew it was possible...I was asking for advice HOW. WHAT are the
          right tools?
          >
          Below is the script I'm using. In this case "TOTALCHARG ES" is the
          "foo" I'm looking for, but I need it to specifically get A's and not
          B's.
          If someone can point me to where I can find out how, I'd appreciate
          it!
          [...]
          >
          You don't have to write your own parser. Use the SimpleXML extension
          with some XPath expressions to get all the nodes you want.
          >
          In my opinion, writing several lines of script in standard PHP is a
          LOT easier than installing an extension (and learning how to install
          an extension as I've never done that before.)
          >
          Why re-invent the wheel? SimpleXML (and the more powerful DOM) are
          standard extensions and should be installed and enabled by default in
          every recent PHP. We are talking about PHP 5, right?
          >
          IF that's the ONLY way to do what I need to do, then so be it. I'll
          figure out how to install SimpleXML and how to use XPath.
          >
          Check phpinfo() to see if SimpleXML is already there (it should be).
          Then check the manual for some examples on how to use it with XPath
          syntax to fetch arbitrary elements from an XML tree. Can't get any
          easier.
          Nope, PHP 4.3.9... there's a reason why our site can't use PHP5
          yet...but I don't recall. One of the other developers are saying a
          hundred pages will have to be rewritten before we can convert
          otherwise it will completely mess up our e-commerce site.
          So no, SimpleXML is not found in my phpinfo(). =/

          Comment

          • news@celticbear.com

            #6
            Re: getting the right XML tag in the parse.

            On Jul 18, 2:47 pm, "n...@celticbea r.com" <n...@celticbea r.comwrote:
            On Jul 18, 2:29 pm, Michael Fesser <neti...@gmx.de wrote:
            >
            >
            >
            .oO(n...@celtic bear.com)
            >
            >On Jul 18, 10:51 am, Michael Fesser <neti...@gmx.de wrote:
            >
            >I need the value of A's "foo", not B's "foo". But from what I can find
            >I can only get the value of the lowest nested tag in a nest. i.e.:
            >"foo" or "BAR". Not specifically A or B's "foo".
            >
            >Of course you can access every element and every attribute in the tree.
            >Just use the right tools.
            >
            >I knew it was possible...I was asking for advice HOW. WHAT are the
            >right tools?
            >
            >Below is the script I'm using. In this case "TOTALCHARG ES" is the
            >"foo" I'm looking for, but I need it to specifically get A's and not
            >B's.
            >If someone can point me to where I can find out how, I'd appreciate
            >it!
            >[...]
            >
            >You don't have to write your own parser. Use the SimpleXML extension
            >with some XPath expressions to get all the nodes you want.
            >
            >In my opinion, writing several lines of script in standard PHP is a
            >LOT easier than installing an extension (and learning how to install
            >an extension as I've never done that before.)
            >
            Why re-invent the wheel? SimpleXML (and the more powerful DOM) are
            standard extensions and should be installed and enabled by default in
            every recent PHP. We are talking about PHP 5, right?
            >
            >IF that's the ONLY way to do what I need to do, then so be it. I'll
            >figure out how to install SimpleXML and how to use XPath.
            >
            Check phpinfo() to see if SimpleXML is already there (it should be).
            Then check the manual for some examples on how to use it with XPath
            syntax to fetch arbitrary elements from an XML tree. Can't get any
            easier.
            >
            Nope, PHP 4.3.9... there's a reason why our site can't use PHP5
            yet...but I don't recall. One of the other developers are saying a
            hundred pages will have to be rewritten before we can convert
            otherwise it will completely mess up our e-commerce site.
            So no, SimpleXML is not found in my phpinfo(). =/
            But it does have domxml, if that means anything:

            domxml
            DOM/XML enabled
            DOM/XML API Version 20020815
            libxml Version 20616
            HTML Support enabled
            XPath Support enabled
            XPointer Support enabled
            DOM/XSLT enabled
            libxslt Version 1.1.11
            libxslt compiled against libxml Version 2.6.16
            DOM/EXSLT enabled
            libexslt Version 1.1.11

            Comment

            • Paul Lautman

              #7
              Re: getting the right XML tag in the parse.

              news@celticbear .com wrote:
              On Jul 18, 2:47 pm, "n...@celticbea r.com" <n...@celticbea r.comwrote:
              >On Jul 18, 2:29 pm, Michael Fesser <neti...@gmx.de wrote:
              >>
              >>
              >>
              .oO(n...@celtic bear.com)
              >>
              >On Jul 18, 10:51 am, Michael Fesser <neti...@gmx.de wrote:
              >>
              >I need the value of A's "foo", not B's "foo". But from what I
              >can find I can only get the value of the lowest nested tag in
              >a nest. i.e.: "foo" or "BAR". Not specifically A or B's "foo".
              >>
              >Of course you can access every element and every attribute in
              >the tree. Just use the right tools.
              >>
              >I knew it was possible...I was asking for advice HOW. WHAT are the
              >right tools?
              >>
              >Below is the script I'm using. In this case "TOTALCHARG ES" is
              >the "foo" I'm looking for, but I need it to specifically get
              >A's and not B's.
              >If someone can point me to where I can find out how, I'd
              >appreciate it!
              >[...]
              >>
              >You don't have to write your own parser. Use the SimpleXML
              >extension with some XPath expressions to get all the nodes you
              >want.
              >>
              >In my opinion, writing several lines of script in standard PHP is
              >a LOT easier than installing an extension (and learning how to
              >install an extension as I've never done that before.)
              >>
              Why re-invent the wheel? SimpleXML (and the more powerful DOM) are
              standard extensions and should be installed and enabled by default
              in every recent PHP. We are talking about PHP 5, right?
              >>
              >IF that's the ONLY way to do what I need to do, then so be it.
              >I'll figure out how to install SimpleXML and how to use XPath.
              >>
              Check phpinfo() to see if SimpleXML is already there (it should
              be). Then check the manual for some examples on how to use it with
              XPath syntax to fetch arbitrary elements from an XML tree. Can't
              get any easier.
              >>
              >Nope, PHP 4.3.9... there's a reason why our site can't use PHP5
              >yet...but I don't recall. One of the other developers are saying a
              >hundred pages will have to be rewritten before we can convert
              >otherwise it will completely mess up our e-commerce site.
              >So no, SimpleXML is not found in my phpinfo(). =/
              How about: http://www.phpclasses.org/browse/file/22596.html
              no extensions to load.


              Comment

              • cwdjrxyz

                #8
                Re: getting the right XML tag in the parse.

                On Jul 18, 2:47 pm, "n...@celticbea r.com" <n...@celticbea r.comwrote:
                On Jul 18, 2:29 pm, Michael Fesser <neti...@gmx.de wrote:
                >
                >
                >
                .oO(n...@celtic bear.com)
                >
                >On Jul 18, 10:51 am, Michael Fesser <neti...@gmx.de wrote:
                >
                >I need the value of A's "foo", not B's "foo". But from what I can find
                >I can only get the value of the lowest nested tag in a nest. i.e.:
                >"foo" or "BAR". Not specifically A or B's "foo".
                >
                >Of course you can access every element and every attribute in the tree.
                >Just use the right tools.
                >
                >I knew it was possible...I was asking for advice HOW. WHAT are the
                >right tools?
                >
                >Below is the script I'm using. In this case "TOTALCHARG ES" is the
                >"foo" I'm looking for, but I need it to specifically get A's and not
                >B's.
                >If someone can point me to where I can find out how, I'd appreciate
                >it!
                >[...]
                >
                >You don't have to write your own parser. Use the SimpleXML extension
                >with some XPath expressions to get all the nodes you want.
                >
                >In my opinion, writing several lines of script in standard PHP is a
                >LOT easier than installing an extension (and learning how to install
                >an extension as I've never done that before.)
                >
                Why re-invent the wheel? SimpleXML (and the more powerful DOM) are
                standard extensions and should be installed and enabled by default in
                every recent PHP. We are talking about PHP 5, right?
                >
                >IF that's the ONLY way to do what I need to do, then so be it. I'll
                >figure out how to install SimpleXML and how to use XPath.
                >
                Check phpinfo() to see if SimpleXML is already there (it should be).
                Then check the manual for some examples on how to use it with XPath
                syntax to fetch arbitrary elements from an XML tree. Can't get any
                easier.
                >
                Nope, PHP 4.3.9... there's a reason why our site can't use PHP5
                yet...but I don't recall. One of the other developers are saying a
                hundred pages will have to be rewritten before we can convert
                otherwise it will completely mess up our e-commerce site.
                So no, SimpleXML is not found in my phpinfo(). =/
                If I remember correctly, it sometimes is possible to have 2 versions
                of php on a server. In your case that would mean keeping your current
                version of 4 as primary for the extension .php and using the
                extension .php5 for the new 5 version. If that can be done and you can
                find someone to do it for your server, then you perhaps could keep all
                happy. I recently moved my two domains and a subdomain from an old
                server that supported php 4 only to a new server that supports php 5
                only. There were only a very few minor problems with any of my pages,
                and no problems with the php upgrade. Of course some others may have
                written code, some of which even predates php4, that causes problems
                on an upgrade to php5.

                Comment

                • news@celticbear.com

                  #9
                  Re: getting the right XML tag in the parse.

                  On Jul 18, 3:47 pm, cwdjrxyz <spamtr...@cwdj r.infowrote:
                  On Jul 18, 2:47 pm, "n...@celticbea r.com" <n...@celticbea r.comwrote:
                  >
                  >
                  >
                  On Jul 18, 2:29 pm, Michael Fesser <neti...@gmx.de wrote:
                  >
                  .oO(n...@celtic bear.com)
                  >
                  On Jul 18, 10:51 am, Michael Fesser <neti...@gmx.de wrote:
                  >
                  I need the value of A's "foo", not B's "foo". But from what I canfind
                  I can only get the value of the lowest nested tag in a nest. i.e.:
                  "foo" or "BAR". Not specifically A or B's "foo".
                  >
                  Of course you can access every element and every attribute in the tree.
                  Just use the right tools.
                  >
                  I knew it was possible...I was asking for advice HOW. WHAT are the
                  right tools?
                  >
                  Below is the script I'm using. In this case "TOTALCHARG ES" is the
                  "foo" I'm looking for, but I need it to specifically get A's and not
                  B's.
                  If someone can point me to where I can find out how, I'd appreciate
                  it!
                  [...]
                  >
                  You don't have to write your own parser. Use the SimpleXML extension
                  with some XPath expressions to get all the nodes you want.
                  >
                  In my opinion, writing several lines of script in standard PHP is a
                  LOT easier than installing an extension (and learning how to install
                  an extension as I've never done that before.)
                  >
                  Why re-invent the wheel? SimpleXML (and the more powerful DOM) are
                  standard extensions and should be installed and enabled by default in
                  every recent PHP. We are talking about PHP 5, right?
                  >
                  IF that's the ONLY way to do what I need to do, then so be it. I'll
                  figure out how to install SimpleXML and how to use XPath.
                  >
                  Check phpinfo() to see if SimpleXML is already there (it should be).
                  Then check the manual for some examples on how to use it with XPath
                  syntax to fetch arbitrary elements from an XML tree. Can't get any
                  easier.
                  >
                  Nope, PHP 4.3.9... there's a reason why our site can't use PHP5
                  yet...but I don't recall. One of the other developers are saying a
                  hundred pages will have to be rewritten before we can convert
                  otherwise it will completely mess up our e-commerce site.
                  So no, SimpleXML is not found in my phpinfo(). =/
                  >
                  If I remember correctly, it sometimes is possible to have 2 versions
                  of php on a server. In your case that would mean keeping your current
                  version of 4 as primary for the extension .php and using the
                  extension .php5 for the new 5 version. If that can be done and you can
                  find someone to do it for your server, then you perhaps could keep all
                  happy. I recently moved my two domains and a subdomain from an old
                  server that supported php 4 only to a new server that supports php 5
                  only. There were only a very few minor problems with any of my pages,
                  and no problems with the php upgrade. Of course some others may have
                  written code, some of which even predates php4, that causes problems
                  on an upgrade to php5.
                  Hmm, cool. Thanks for the reply! I'll check into that.
                  -Liam

                  Comment

                  • Jerry Stuckle

                    #10
                    Re: getting the right XML tag in the parse.

                    news@celticbear .com wrote:
                    On Jul 18, 3:47 pm, cwdjrxyz <spamtr...@cwdj r.infowrote:
                    >On Jul 18, 2:47 pm, "n...@celticbea r.com" <n...@celticbea r.comwrote:
                    >>
                    >>
                    >>
                    >>On Jul 18, 2:29 pm, Michael Fesser <neti...@gmx.de wrote:
                    >>>.oO(n...@cel ticbear.com)
                    >>>>On Jul 18, 10:51 am, Michael Fesser <neti...@gmx.de wrote:
                    >>>>>>I need the value of A's "foo", not B's "foo". But from what I can find
                    >>>>>>I can only get the value of the lowest nested tag in a nest. i.e.:
                    >>>>>>"foo" or "BAR". Not specifically A or B's "foo".
                    >>>>>Of course you can access every element and every attribute in the tree.
                    >>>>>Just use the right tools.
                    >>>>I knew it was possible...I was asking for advice HOW. WHAT are the
                    >>>>right tools?
                    >>>>>>Below is the script I'm using. In this case "TOTALCHARG ES" is the
                    >>>>>>"foo" I'm looking for, but I need it to specifically get A's and not
                    >>>>>>B's.
                    >>>>>>If someone can point me to where I can find out how, I'd appreciate
                    >>>>>>it!
                    >>>>>>[...]
                    >>>>>You don't have to write your own parser. Use the SimpleXML extension
                    >>>>>with some XPath expressions to get all the nodes you want.
                    >>>>In my opinion, writing several lines of script in standard PHP is a
                    >>>>LOT easier than installing an extension (and learning how to install
                    >>>>an extension as I've never done that before.)
                    >>>Why re-invent the wheel? SimpleXML (and the more powerful DOM) are
                    >>>standard extensions and should be installed and enabled by default in
                    >>>every recent PHP. We are talking about PHP 5, right?
                    >>>>IF that's the ONLY way to do what I need to do, then so be it. I'll
                    >>>>figure out how to install SimpleXML and how to use XPath.
                    >>>Check phpinfo() to see if SimpleXML is already there (it should be).
                    >>>Then check the manual for some examples on how to use it with XPath
                    >>>syntax to fetch arbitrary elements from an XML tree. Can't get any
                    >>>easier.
                    >>Nope, PHP 4.3.9... there's a reason why our site can't use PHP5
                    >>yet...but I don't recall. One of the other developers are saying a
                    >>hundred pages will have to be rewritten before we can convert
                    >>otherwise it will completely mess up our e-commerce site.
                    >>So no, SimpleXML is not found in my phpinfo(). =/
                    >If I remember correctly, it sometimes is possible to have 2 versions
                    >of php on a server. In your case that would mean keeping your current
                    >version of 4 as primary for the extension .php and using the
                    >extension .php5 for the new 5 version. If that can be done and you can
                    >find someone to do it for your server, then you perhaps could keep all
                    >happy. I recently moved my two domains and a subdomain from an old
                    >server that supported php 4 only to a new server that supports php 5
                    >only. There were only a very few minor problems with any of my pages,
                    >and no problems with the php upgrade. Of course some others may have
                    >written code, some of which even predates php4, that causes problems
                    >on an upgrade to php5.
                    >
                    Hmm, cool. Thanks for the reply! I'll check into that.
                    -Liam
                    >
                    Yes, you need to get on PHP5 ASAP. PHP4 is at end of life - there will
                    not be any patches any more for it - not even security patches. So
                    you're running a completely unsupported product.

                    Not to say there hasn't been warning - about 2 years worth.

                    But virtually everything I've ever had on PHP4 runs fine on PHP5. If
                    your have a lot of pages which don't work right, chances are someone was
                    doing something rather flaky in the first place. There just aren't THAT
                    many incompatibiliti es between the two.

                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstucklex@attgl obal.net
                    =============== ===

                    Comment

                    • news@celticbear.com

                      #11
                      Re: getting the right XML tag in the parse.

                      On Jul 18, 7:45 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                      n...@celticbear .com wrote:
                      On Jul 18, 3:47 pm, cwdjrxyz <spamtr...@cwdj r.infowrote:
                      On Jul 18, 2:47 pm, "n...@celticbea r.com" <n...@celticbea r.comwrote:
                      >
                      >On Jul 18, 2:29 pm, Michael Fesser <neti...@gmx.de wrote:
                      >>.oO(n...@celt icbear.com)
                      >>>On Jul 18, 10:51 am, Michael Fesser <neti...@gmx.de wrote:
                      >>>>>I need the value of A's "foo", not B's "foo". But from what I canfind
                      >>>>>I can only get the value of the lowest nested tag in a nest. i.e.:
                      >>>>>"foo" or "BAR". Not specifically A or B's "foo".
                      >>>>Of course you can access every element and every attribute in the tree.
                      >>>>Just use the right tools.
                      >>>I knew it was possible...I was asking for advice HOW. WHAT are the
                      >>>right tools?
                      >>>>>Below is the script I'm using. In this case "TOTALCHARG ES" is the
                      >>>>>"foo" I'm looking for, but I need it to specifically get A's and not
                      >>>>>B's.
                      >>>>>If someone can point me to where I can find out how, I'd appreciate
                      >>>>>it!
                      >>>>>[...]
                      >>>>You don't have to write your own parser. Use the SimpleXML extension
                      >>>>with some XPath expressions to get all the nodes you want.
                      >>>In my opinion, writing several lines of script in standard PHP is a
                      >>>LOT easier than installing an extension (and learning how to install
                      >>>an extension as I've never done that before.)
                      >>Why re-invent the wheel? SimpleXML (and the more powerful DOM) are
                      >>standard extensions and should be installed and enabled by default in
                      >>every recent PHP. We are talking about PHP 5, right?
                      >>>IF that's the ONLY way to do what I need to do, then so be it. I'll
                      >>>figure out how to install SimpleXML and how to use XPath.
                      >>Check phpinfo() to see if SimpleXML is already there (it should be).
                      >>Then check the manual for some examples on how to use it with XPath
                      >>syntax to fetch arbitrary elements from an XML tree. Can't get any
                      >>easier.
                      >Nope, PHP 4.3.9... there's a reason why our site can't use PHP5
                      >yet...but I don't recall. One of the other developers are saying a
                      >hundred pages will have to be rewritten before we can convert
                      >otherwise it will completely mess up our e-commerce site.
                      >So no, SimpleXML is not found in my phpinfo(). =/
                      If I remember correctly, it sometimes is possible to have 2 versions
                      of php on a server. In your case that would mean keeping your current
                      version of 4 as primary for the extension .php and using the
                      extension .php5 for the new 5 version. If that can be done and you can
                      find someone to do it for your server, then you perhaps could keep all
                      happy. I recently moved my two domains and a subdomain from an old
                      server that supported php 4 only to a new server that supports php 5
                      only. There were only a very few minor problems with any of my pages,
                      and no problems with the php upgrade. Of course some others may have
                      written code, some of which even predates php4, that causes problems
                      on an upgrade to php5.
                      >
                      Hmm, cool. Thanks for the reply! I'll check into that.
                      -Liam
                      >
                      Yes, you need to get on PHP5 ASAP.  PHP4 is at end of life - there will
                      not be any patches any more for it - not even security patches.  So
                      you're running a completely unsupported product.
                      >
                      Not to say there hasn't been warning - about 2 years worth.
                      >
                      But virtually everything I've ever had on PHP4 runs fine on PHP5.  If
                      your have a lot of pages which don't work right, chances are someone was
                      doing something rather flaky in the first place.  There just aren't THAT
                      many incompatibiliti es between the two.
                      Yeah, someone was doing something flaky in the first place. We have
                      "layout" scripts written back in the time of PHP 3 that utilize
                      ImageMagick and PDFLib, and something about the way they're written
                      messes up under PHP5. There's a LOT of problems with our site! Lots.
                      I've tried to correct as much as I can the last couple of years but
                      there's still so much that requires rewriting.

                      In the meantime, I have to add features that have to get working ASAP
                      before I can continue trying to overhaul.

                      Comment

                      • news@celticbear.com

                        #12
                        Re: getting the right XML tag in the parse.

                        On Jul 18, 3:12 pm, "Paul Lautman" <paul.laut...@b tinternet.com>
                        wrote:
                        n...@celticbear .com wrote:
                        On Jul 18, 2:47 pm, "n...@celticbea r.com" <n...@celticbea r.comwrote:
                        On Jul 18, 2:29 pm, Michael Fesser <neti...@gmx.de wrote:
                        >
                        .oO(n...@celtic bear.com)
                        >
                        >On Jul 18, 10:51 am, Michael Fesser <neti...@gmx.de wrote:
                        >
                        >I need the value of A's "foo", not B's "foo". But from what I
                        >can find I can only get the value of the lowest nested tag in
                        >a nest. i.e.: "foo" or "BAR". Not specifically A or B's "foo".
                        >
                        >Of course you can access every element and every attribute in
                        >the tree. Just use the right tools.
                        >
                        >I knew it was possible...I was asking for advice HOW. WHAT are the
                        >right tools?
                        >
                        >Below is the script I'm using. In this case "TOTALCHARG ES" is
                        >the "foo" I'm looking for, but I need it to specifically get
                        >A's and not B's.
                        >If someone can point me to where I can find out how, I'd
                        >appreciate it!
                        >[...]
                        >
                        >You don't have to write your own parser. Use the SimpleXML
                        >extension with some XPath expressions to get all the nodes you
                        >want.
                        >
                        >In my opinion, writing several lines of script in standard PHP is
                        >a LOT easier than installing an extension (and learning how to
                        >install an extension as I've never done that before.)
                        >
                        Why re-invent the wheel? SimpleXML (and the more powerful DOM) are
                        standard extensions and should be installed and enabled by default
                        in every recent PHP. We are talking about PHP 5, right?
                        >
                        >IF that's the ONLY way to do what I need to do, then so be it.
                        >I'll figure out how to install SimpleXML and how to use XPath.
                        >
                        Check phpinfo() to see if SimpleXML is already there (it should
                        be). Then check the manual for some examples on how to use it with
                        XPath syntax to fetch arbitrary elements from an XML tree. Can't
                        get any easier.
                        >
                        Nope, PHP 4.3.9... there's a reason why our site can't use PHP5
                        yet...but I don't recall. One of the other developers are saying a
                        hundred pages will have to be rewritten before we can convert
                        otherwise it will completely mess up our e-commerce site.
                        So no, SimpleXML is not found in my phpinfo(). =/
                        >
                        How about:http://www.phpclasses.org/browse/file/22596.html
                        no extensions to load.
                        OK, this is ridiculous...ho w does one install a class?
                        By the looks of it, this is just a PHP script that maybe I just need
                        to include() at the top of other pages, but I'm not sure.
                        The phpclasses site has no help on what to DO with these class pages,
                        and googling isn't coming up with anything.
                        This is probably a very stupid question, no, I'm certain it is, but
                        what do I DO with this simplexlm.class .php?
                        Thanks

                        Comment

                        • Michael Fesser

                          #13
                          Re: getting the right XML tag in the parse.

                          ..oO(news@celti cbear.com)
                          >On Jul 18, 3:12 pm, "Paul Lautman" <paul.laut...@b tinternet.com>
                          >wrote:
                          >>
                          >How about:http://www.phpclasses.org/browse/file/22596.html
                          >no extensions to load.
                          >
                          >OK, this is ridiculous...ho w does one install a class?
                          >By the looks of it, this is just a PHP script that maybe I just need
                          >to include() at the top of other pages, but I'm not sure.
                          >The phpclasses site has no help on what to DO with these class pages,
                          >and googling isn't coming up with anything.
                          >This is probably a very stupid question, no, I'm certain it is, but
                          >what do I DO with this simplexlm.class .php?
                          You've already answered it: You just 'include' or 'require' it.

                          Micha

                          Comment

                          • sheldonlg

                            #14
                            Re: getting the right XML tag in the parse.

                            news@celticbear .com wrote:
                            On Jul 18, 3:12 pm, "Paul Lautman" <paul.laut...@b tinternet.com>
                            wrote:
                            >n...@celticbea r.com wrote:
                            >>On Jul 18, 2:47 pm, "n...@celticbea r.com" <n...@celticbea r.comwrote:
                            >>>On Jul 18, 2:29 pm, Michael Fesser <neti...@gmx.de wrote:
                            >>>>.oO(n...@ce lticbear.com)
                            >>>>>On Jul 18, 10:51 am, Michael Fesser <neti...@gmx.de wrote:
                            >>>>>>>I need the value of A's "foo", not B's "foo". But from what I
                            >>>>>>>can find I can only get the value of the lowest nested tag in
                            >>>>>>>a nest. i.e.: "foo" or "BAR". Not specifically A or B's "foo".
                            >>>>>>Of course you can access every element and every attribute in
                            >>>>>>the tree. Just use the right tools.
                            >>>>>I knew it was possible...I was asking for advice HOW. WHAT are the
                            >>>>>right tools?
                            >>>>>>>Below is the script I'm using. In this case "TOTALCHARG ES" is
                            >>>>>>>the "foo" I'm looking for, but I need it to specifically get
                            >>>>>>>A's and not B's.
                            >>>>>>>If someone can point me to where I can find out how, I'd
                            >>>>>>>apprecia te it!
                            >>>>>>>[...]
                            >>>>>>You don't have to write your own parser. Use the SimpleXML
                            >>>>>>extensi on with some XPath expressions to get all the nodes you
                            >>>>>>want.
                            >>>>>In my opinion, writing several lines of script in standard PHP is
                            >>>>>a LOT easier than installing an extension (and learning how to
                            >>>>>install an extension as I've never done that before.)
                            >>>>Why re-invent the wheel? SimpleXML (and the more powerful DOM) are
                            >>>>standard extensions and should be installed and enabled by default
                            >>>>in every recent PHP. We are talking about PHP 5, right?
                            >>>>>IF that's the ONLY way to do what I need to do, then so be it.
                            >>>>>I'll figure out how to install SimpleXML and how to use XPath.
                            >>>>Check phpinfo() to see if SimpleXML is already there (it should
                            >>>>be). Then check the manual for some examples on how to use it with
                            >>>>XPath syntax to fetch arbitrary elements from an XML tree. Can't
                            >>>>get any easier.
                            >>>Nope, PHP 4.3.9... there's a reason why our site can't use PHP5
                            >>>yet...but I don't recall. One of the other developers are saying a
                            >>>hundred pages will have to be rewritten before we can convert
                            >>>otherwise it will completely mess up our e-commerce site.
                            >>>So no, SimpleXML is not found in my phpinfo(). =/
                            >How about:http://www.phpclasses.org/browse/file/22596.html
                            >no extensions to load.
                            >
                            OK, this is ridiculous...ho w does one install a class?
                            By the looks of it, this is just a PHP script that maybe I just need
                            to include() at the top of other pages, but I'm not sure.
                            Correct. You then instantiate an object of that class with the "new"
                            statement.

                            require_once 'somewhere/foo.php';
                            $fooObj = new foo();
                            $thisOne = $foo->a_foo_method() ;
                            The phpclasses site has no help on what to DO with these class pages,
                            and googling isn't coming up with anything.
                            This is probably a very stupid question, no, I'm certain it is, but
                            what do I DO with this simplexlm.class .php?
                            Thanks

                            Comment

                            • news@celticbear.com

                              #15
                              Re: getting the right XML tag in the parse.

                              On Jul 18, 10:16 am, "n...@celticbea r.com" <n...@celticbea r.com>
                              wrote:
                              I'm trying to parse an XML formatted post reply, and I can't figure
                              out how to get the value of the right tag.
                              The XML is formatted like this:
                              >
                              <A>
                                 <foo>val1</foo>
                              </A>
                              <B>
                                 <foo>val2</foo>
                              </B>
                              <BAR>
                                 val3
                              </BAR>
                              >
                              I need the value of A's "foo", not B's "foo". But from what I can find
                              I can only get the value of the lowest nested tag in a nest. i.e.:
                              "foo" or "BAR". Not specifically A or B's "foo".
                              Below is the script I'm using. In this case "TOTALCHARG ES" is the
                              "foo" I'm looking for, but I need it to specifically get A's and not
                              B's.
                              If someone can point me to where I can find out how, I'd appreciate
                              it!
                              -Liam
                              >
                              //Defines startElement function
                              function startElement($x ml_parser, $element_name, $element_attrs) {
                                      global $printout, $tag, $output1;
                              >
                                      switch($element _name) {
                                              case "TOTALCHARG ES":
                                                      $printout = true;
                                                      $tag = "TOTALCHARG ES";
                                                      break;
                                      }
                              >
                              }
                              >
                              //Defines endElement function
                              function endElement($xml _parser, $element_name) {
                                      global $printout, $tag, $output1;
                              >
                                      switch($element _name) {
                                              case "TOTALCHARG ES":
                                                      $printout = false;
                                                      $tag = "";
                                                      break;
                                      }
                              >
                              }
                              >
                              //Defines characterData function
                              function characterData($ xml_parser, $fp) {
                                      global $printout, $tag, $output1;
                              >
                                      if (($tag=="TOTALC HARGES") && ($printout==tru e)) {
                                              $output1 = $fp;
                                              //echo $output;
                                      }
                                      return $output1;
                              >
                              }
                              >
                              >
                              OK, back to my original question:
                              Based on some of the replies, I'm renewing my efforts to see what it
                              will take to fix the many problematic pages that is preventing
                              migrating to PHP5.
                              In the meantime, I have to use xml_parser in PHP4.
                              Is there really no way to tell the xml_parser that I'm looking for the
                              value of a tag that happens to share the same name as another tag, but
                              belonging to a separate parent tag?
                              Like, if this were MySQL, getting the value of "bar" from foo.bar
                              instead of oof.bar?
                              Thanks

                              Comment

                              Working...