programmers - help with xml feed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • georgeyw
    58008 53773
    • Jul 2005
    • 9865

    #1

    programmers - help with xml feed

    So I am trying to read in an xml feed with php, however the feed has thrown me a bit of a curve ball.

    It starts off as a normal xml feed, however mid way it changes and this is what is throwing me. How do I handle a feed that does the following : ?

    PHP Code:
    <element>
     <item>
      <itemid>
      </itemid>
     </item>
     <item>
      <itemid>
      </itemid>
     </item>
     <item>
      <itemid>
      </itemid>
     </item>
     <item>
      <itemid>
      </itemid>
     </item>
    
    <!---- Then it changes ---->
    <newelement>
     <newsubelement>
      <item>
      <itemid>
      </itemid>
      </item>
      <item>
      <itemid>
      </itemid>
      </item>
      <item>
      <itemid>
      </itemid>
      </item>
     </newsubelement>
     <newsubelement>
      <item>
      <itemid>
      </itemid>
      </item>
      <item>
      <itemid>
      </itemid>
      </item>
      <item>
      <itemid>
      </itemid>
      </item>
      <item>
      <itemid>
      </itemid>
      </item>
     </newsubelement>
    </element> 
    
    Any help would be much appreciated!

    cheers
    TripleXPrint on Megan Fox
    "I would STILL suck her pussy until her face caved in. And then blow her up and do it again!"
  • superman1
    Registered User
    • Dec 2013
    • 49

    #2
    the right way: request to from the source of xml to send valid xml :-)

    alternative way: sanitize the data, fix the xml or extract data with regexp -> but both is not the right way....

    Comment

    • georgeyw
      58008 53773
      • Jul 2005
      • 9865

      #3
      Originally posted by superman1
      the right way: request to from the source of xml to send valid xml :-)

      alternative way: sanitize the data, fix the xml or extract data with regexp -> but both is not the right way....
      haha well not possible to get them to change it at all unfortunately.

      Was hoping for a way to loop through without having to sanitize the data as you mentioned.

      Thanks for the reply.
      TripleXPrint on Megan Fox
      "I would STILL suck her pussy until her face caved in. And then blow her up and do it again!"

      Comment

      • EddyTheDog
        Just Doing My Own Thing
        • Jan 2011
        • 25433

        #4
        I feed most XML through DreamWeaver and add it as a recordset - It is pretty good at sorting out strange looking XML like that...

        Comment

        • georgeyw
          58008 53773
          • Jul 2005
          • 9865

          #5
          Originally posted by EddyTheDog
          I feed most XML through DreamWeaver and add it as a recordset - It is pretty good at sorting out strange looking XML like that...
          The problem is, I want to set it up with a cronjob so my code can read the xml - add updates if there are any otherwise leave everything until the next time the cronjob runs

          Right now, I can read in bits of the xml feed, but not all of it because they have made it in such a shit of a way.
          TripleXPrint on Megan Fox
          "I would STILL suck her pussy until her face caved in. And then blow her up and do it again!"

          Comment

          • georgeyw
            58008 53773
            • Jul 2005
            • 9865

            #6
            Bump?............
            TripleXPrint on Megan Fox
            "I would STILL suck her pussy until her face caved in. And then blow her up and do it again!"

            Comment

            • superman1
              Registered User
              • Dec 2013
              • 49

              #7
              I'm not sure if I catch the realy problem, does PHP accept the XML you get or you get there a error? If Simple XML or whatever engine you use take it, you could use xpath to get what you need.

              Comment

              • fris
                Too lazy to set a custom title
                • Aug 2002
                • 55679

                #8
                can you give me a live url to the xml feed so i can give you the code?

                chris @ lod.com
                Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

                Comment

                • Barry-xlovecam
                  It's 42
                  • Jun 2010
                  • 18083

                  #9
                  XML Parsing Error: mismatched tag. Expected: </newelement>.
                  Location: ****
                  Line Number 53, Column 3:</element>
                  --^

                  Bad posting paste job?

                  At any rate try a data dump and look at the array.
                  You may need to use Xpath
                  Last edited by Barry-xlovecam; 04-29-2014, 10:07 AM.

                  Comment

                  • Barry-xlovecam
                    It's 42
                    • Jun 2010
                    • 18083

                    #10
                    Code:
                    $VAR1 = {
                              'item' => [
                                        {
                                          'itemid' => {}
                                        },
                                        {
                                          'itemid' => {}
                                        },
                                        {
                                          'itemid' => {}
                                        },
                                        {
                                          'itemid' => {}
                                        }
                                      ],
                              'newelement' => {
                                              'newsubelement' => [
                                                                 {
                                                                   'item' => [
                                                                             {
                                                                               'itemid' => {}
                                                                             },
                                                                             {
                                                                               'itemid' => {}
                                                                             },
                                                                             {
                                                                               'itemid' => {}
                                                                             }
                                                                           ]
                                                                 },
                                                                 {
                                                                   'item' => [
                                                                             {
                                                                               'itemid' => {}
                                                                             },
                                                                             {
                                                                               'itemid' => {}
                                                                             },
                                                                             {
                                                                               'itemid' => {}
                                                                             },
                                                                             {
                                                                               'itemid' => {}
                                                                             }
                                                                           ]
                                                                 }
                                                               ]
                                            }
                            };

                    Comment

                    • freecartoonporn
                      Confirmed User
                      • Jan 2012
                      • 7683

                      #11
                      create 1 php to sanitize data and or format the wront xml to correct xml,, then use your regular xml code to parse the xml.

                      or you can just create one file of it.
                      SSD Cloud Server, VPS Server, Simple Cloud Hosting | DigitalOcean

                      Comment

                      • Milan_Quantox
                        Confirmed User
                        • Aug 2012
                        • 1768

                        #12
                        You have elements and subelements. Please send me whole code you used to parse this, and one of my devs will fix it for you [email protected]

                        Comment

                        Working...