How can I extract data of an external XML to PHP?

How can I extract data from a Microsoft Project 2003 XML File to a text file?

  • I am in need of suggestions on how to quickly go through an XML file and extract certain data from the file.  The XML file I am using is one that was generated from Microsoft Project 2003.  I need to extract specific parent and task information from the file and write it to a text file.  Currently I am using a Python program, however, due to the large XML files I am working with and the need to extract a lot of different data it is slow (up to 80 sec to run for a 250 line project file).  I was looking for a solution or another programming language that handles XML files quickly and efficiently.

  • Answer:

    80 seconds seems like a very long time for such a small file. If you can get your head around XSLT, particularly XSLT v2, it would be worth the investment. XSLT is a very expressive and powerful XML processing language. XSLT v2 adds grouping and multple document output capabilities that were lacking from XSLT v1. XSLT isn't quite as powerful as SQL but it comes close. One nice thing about XSLT is that you can often render directly to a browser simply by including a stylesheet processing instruction in your XML file. There aren't that many XSLT v2 implementations out there, but I have used this one http://saxon.sourceforge.net/.

Jon Seymour at Quora Visit the source

Was this solution helpful to you?

Other answers

Also would suggest XSLT. See some tutorials here: http://www.w3schools.com/xsl/default.asp Also may want to check: http://servingxml.sourceforge.net/ It is some software for XML data transformation.

John Sommer

I will look more into the suggestions.  I did look up XSLT and found a link to XPath.  I took the tutorial on XPath which helped me write code for a new python XML parser I tried called cElementTree.  Before I was using minidom to parse my XML in Python and when I tried cElementTree it was significantly faster. I have to finish creating all the logic in my code but I was able to do what took 80 sec before in 2 secs now.  I should have added to the question I posted the fact that I will have to do this extraction on around 50 to 100 XML files one after another so 80 sec a file would have taken all night.  Thanks again for your help!

Justin Sommer

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.