php - Parsing the Google Reader export -


I am trying to use SimpleXML to parse the XML file produced from Google Reader export.

Example of the file:

  & lt ;? XML version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Opml version = "1.0" & gt; & Lt; Top & gt; & Lt; Title & gt; TheTechBox subscription in Google Reader & lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Outline Text = "Engadget RSS Feeds" Title = "Engadget RSS Feeds" Type = "RSS" xmlUrl = "http://www.engadget.com/rss.xml" htmlUrl = "http: //www.engadget.com." /> & Lt; Outline text = "xkcd.com" title = "xkcd.com" type = "RSS" xmlUrl = "http://xkcd.com/rss.xml" htmlUrl = "http://xkcd.com/" /> ; & Lt; / Body & gt; & Lt; / OPML & gt;   

The user has tried to upload this file to this form and the form needs to be removed through the loop and to remove the data.

  & lt ;? Php if ($ _FILES ["file"] ["error"]> gt;?) {Echo "error:". $ _FILES ["file"] ["error"]. "& Lt; br & gt;"; } And {$ import = New SimpleXMlelement ($ _ files ["file"] ["name"]); Foreign exchange ($ import-> opml-> body-> outline [0] as feed) {resonance $ feed ["title"]; }}? & Gt;   

Now Chrome generates a server error, which indicates that something is wrong on the page, the file upload is OK, so this is a simple extension part.

I is planning to do something more complex with data later, I am currently trying to resonate the data on the page. (For demo purposes).

Any feedback will be highly appreciated.

Finally has a working code

  $ import = simplexml_load_file ($ _ files ["file"] ["tmp_name"]); Forex Currency ($ Import-> Account-> Feed-> Feed- $ ["Headline"]; }   

All this will need to be added to parse the data but it works.

When you use SimpleXML, you have fallen into the classic trap: if you parsed a file or string The first object to be received is not a "document" object, but the parent node in this case, the parent node and lt; Opml & gt; ... & lt; / Opml & gt; , then your sample code contains $ import that is & lt; Opml & gt; In other words, $ import-> gt; Opml- & gt; Instead of body you need to call only $ import-> body .

There is another bug in your loop, which is the first time you & lt; Outline & gt; All elements ( foreach ($ whatever- whatever- whatever you want) for element ( -> outline [0] ) Looping on & gt; outline feed as outline) ).

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -