problem parsing xml using PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • *

    problem parsing xml using PHP

    I need to devise a way of reading the following XML data and taking the
    Job_ID and putting into a database using the access_code and the
    adt_company_id.

    any idea of how I might be able to do this, im stuck!

    <?xml version="1.0" encoding="Windo ws-1252"?>
    <Sections>

    <SECTION compulsory="0">
    <TITLE><![CDATA[ACCESS_CODE]]></TITLE>
    <BODY><![CDATA[1234]]></BODY>
    <FROM><![CDATA[Database query]]></FROM>
    </SECTION>
    <SECTION compulsory="0">
    <TITLE><![CDATA[ADT_COMPANY_ID]]></TITLE>
    <BODY><![CDATA[70399]]></BODY>
    <FROM><![CDATA[Database query]]></FROM>
    </SECTION>

    <SECTION compulsory="0">
    <TITLE><![CDATA[JOB_ID]]></TITLE>
    <BODY><![CDATA[60905057]]></BODY>
    <FROM><![CDATA[Database query]]></FROM>
    </SECTION>

    </Sections>


  • Andy Hassall

    #2
    Re: problem parsing xml using PHP

    On Fri, 6 Aug 2004 18:06:59 +0100, "*" <*@*.com> wrote:
    [color=blue]
    >I need to devise a way of reading the following XML data and taking the
    >Job_ID and putting into a database using the access_code and the
    >adt_company_id .[/color]

    PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


    --
    Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool
    (v1.4.0 new 1st Aug 2004)

    Comment

    • *

      #3
      Re: problem parsing xml using PHP

      i have looked at that, but cant make head nor tail of it.


      "Andy Hassall" <andy@andyh.co. uk> wrote in message
      news:rbg7h0ptql s33sm3pbs331m81 ntki3ol82@4ax.c om...[color=blue]
      > On Fri, 6 Aug 2004 18:06:59 +0100, "*" <*@*.com> wrote:
      >[color=green]
      > >I need to devise a way of reading the following XML data and taking the
      > >Job_ID and putting into a database using the access_code and the
      > >adt_company_id .[/color]
      >
      > http://php.net/xml
      >
      > --
      > Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
      > <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool
      > (v1.4.0 new 1st Aug 2004)[/color]


      Comment

      • Ian.H

        #4
        Re: problem parsing xml using PHP

        On Fri, 06 Aug 2004 18:06:59 +0100, * wrote:
        [color=blue]
        > I need to devise a way of reading the following XML data and taking the
        > Job_ID and putting into a database using the access_code and the
        > adt_company_id.
        >
        > any idea of how I might be able to do this, im stuck!
        >
        > <?xml version="1.0" encoding="Windo ws-1252"?>
        > <Sections>
        >
        > <SECTION compulsory="0">
        > <TITLE><![CDATA[ACCESS_CODE]]></TITLE>
        > <BODY><![CDATA[1234]]></BODY>
        > <FROM><![CDATA[Database query]]></FROM>
        > </SECTION>
        > <SECTION compulsory="0">
        > <TITLE><![CDATA[ADT_COMPANY_ID]]></TITLE>
        > <BODY><![CDATA[70399]]></BODY>
        > <FROM><![CDATA[Database query]]></FROM>
        > </SECTION>
        >
        > <SECTION compulsory="0">
        > <TITLE><![CDATA[JOB_ID]]></TITLE>
        > <BODY><![CDATA[60905057]]></BODY>
        > <FROM><![CDATA[Database query]]></FROM>
        > </SECTION>
        >
        > </Sections>[/color]


        Could try the PEAR stuff. Although can be slowish on large XML files, it
        works and pretty simply.


        <http://pear.php.net/manual/en/package.xml.xml-tree.php>


        maybe of use, although other XML modules there maybe better suited to your
        exact specifications =)



        Regards,

        Ian

        --
        Ian.H
        digiServ Network
        London, UK


        Comment

        • Chung Leong

          #5
          Re: problem parsing xml using PHP

          "*" <*@*.com> wrote in message news:cf0dos$b0t $1@news.netkone ct.net...[color=blue]
          > I need to devise a way of reading the following XML data and taking the
          > Job_ID and putting into a database using the access_code and the
          > adt_company_id.
          >
          > any idea of how I might be able to do this, im stuck!
          >
          > <?xml version="1.0" encoding="Windo ws-1252"?>
          > <Sections>
          >
          > <SECTION compulsory="0">
          > <TITLE><![CDATA[ACCESS_CODE]]></TITLE>
          > <BODY><![CDATA[1234]]></BODY>
          > <FROM><![CDATA[Database query]]></FROM>
          > </SECTION>
          > <SECTION compulsory="0">
          > <TITLE><![CDATA[ADT_COMPANY_ID]]></TITLE>
          > <BODY><![CDATA[70399]]></BODY>
          > <FROM><![CDATA[Database query]]></FROM>
          > </SECTION>
          >
          > <SECTION compulsory="0">
          > <TITLE><![CDATA[JOB_ID]]></TITLE>
          > <BODY><![CDATA[60905057]]></BODY>
          > <FROM><![CDATA[Database query]]></FROM>
          > </SECTION>
          >
          > </Sections>[/color]

          You can probably solve this more easily with regular expression.


          Comment

          • *

            #6
            Re: problem parsing xml using PHP

            > You can probably solve this more easily with regular expression.[color=blue]
            >[/color]

            i was thinking that myself


            Comment

            • Christopher Finke

              #7
              Re: problem parsing xml using PHP

              "*" <*@*.com> wrote in message news:cf0dos$b0t $1@news.netkone ct.net...[color=blue]
              > I need to devise a way of reading the following XML data and taking the
              > Job_ID and putting into a database using the access_code and the
              > adt_company_id.
              >
              > any idea of how I might be able to do this, im stuck!
              >
              > <?xml version="1.0" encoding="Windo ws-1252"?>
              > <Sections>
              >
              > <SECTION compulsory="0">
              > <TITLE><![CDATA[ACCESS_CODE]]></TITLE>
              > <BODY><![CDATA[1234]]></BODY>
              > <FROM><![CDATA[Database query]]></FROM>
              > </SECTION>
              > <SECTION compulsory="0">
              > <TITLE><![CDATA[ADT_COMPANY_ID]]></TITLE>
              > <BODY><![CDATA[70399]]></BODY>
              > <FROM><![CDATA[Database query]]></FROM>
              > </SECTION>
              >
              > <SECTION compulsory="0">
              > <TITLE><![CDATA[JOB_ID]]></TITLE>
              > <BODY><![CDATA[60905057]]></BODY>
              > <FROM><![CDATA[Database query]]></FROM>
              > </SECTION>
              >
              > </Sections>[/color]

              Something like this should do it:

              preg_match_all( "/SECTION
              compulsory=\"([0-9]*)\".*ACCESS_CO DE.*CDATA\[([0-9]*)\].*ADT_COMPANY_I D.*\[(
              [0-9]*)\].*JOB_ID.*CDATA \[([0-9]*)\]/Uis",$data, $matches, PREG_SET_ORDER) ;

              Then $matches would be an array of these arrays:

              Array (
              [0] => The whole match
              [1] => The number in 'compulsory="## "'
              [2] => The ACCESS_CODE number
              [3] => The ADT_COMPANY_ID number
              [4] => The JOB_ID number
              }

              (There would be one of these arrays for each unique 'compulsory="## "'
              section.)

              Hope this helps,

              Chris Finke



              Comment

              Working...