GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   programmers - help with xml feed (https://gfy.com/showthread.php?t=1139437)

georgeyw 04-29-2014 05:17 AM

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

superman1 04-29-2014 05:38 AM

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....

georgeyw 04-29-2014 05:47 AM

Quote:

Originally Posted by superman1 (Post 20067089)
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.

EddyTheDog 04-29-2014 05:53 AM

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

georgeyw 04-29-2014 05:56 AM

Quote:

Originally Posted by EddyTheDog (Post 20067107)
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.

georgeyw 04-29-2014 06:50 AM

Bump?............

superman1 04-29-2014 06:59 AM

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.

fris 04-29-2014 07:05 AM

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

chris @ lod.com

Barry-xlovecam 04-29-2014 11:04 AM

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

Barry-xlovecam 04-29-2014 11:18 AM

Code:

$VAR1 = {
          'item' => [
                    {
                      'itemid' => {}
                    },
                    {
                      'itemid' => {}
                    },
                    {
                      'itemid' => {}
                    },
                    {
                      'itemid' => {}
                    }
                  ],
          'newelement' => {
                          'newsubelement' => [
                                            {
                                              'item' => [
                                                        {
                                                          'itemid' => {}
                                                        },
                                                        {
                                                          'itemid' => {}
                                                        },
                                                        {
                                                          'itemid' => {}
                                                        }
                                                      ]
                                            },
                                            {
                                              'item' => [
                                                        {
                                                          'itemid' => {}
                                                        },
                                                        {
                                                          'itemid' => {}
                                                        },
                                                        {
                                                          'itemid' => {}
                                                        },
                                                        {
                                                          'itemid' => {}
                                                        }
                                                      ]
                                            }
                                          ]
                        }
        };


freecartoonporn 04-29-2014 07:42 PM

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.

Milan_Quantox 04-30-2014 03:57 AM

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 :thumbsup [email protected]


All times are GMT -7. The time now is 04:03 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123