Jump to content

Parse XML Directly to page vs. Into an Array


denoteone

Recommended Posts

Trying to figure out what's best practice when it comes to parsing XML and echoing it into a pretty little table.

 

should I save all the data in a array and then loop through the array? Or should I just echo the data directly from the XML file?

 

Any thoughts would be welcomed. 

Link to comment
Share on other sites

Trying to figure out what's best practice when it comes to parsing XML and echoing it into a pretty little table.

 

should I save all the data in a array and then loop through the array? Or should I just echo the data directly from the XML file?

 

Any thoughts would be welcomed. 

 

Like ManiacDan mentioned, XSL is the easiest and most efficient way to do this.  You can embed HTML into the XSL sheet and still use CSS to style your HTML.  If you don't want to go this route and still want to use PHP then you can use something like SimpleXML.

Link to comment
Share on other sites

I should have looked into XSL before. My life just got a little easier. Thanks!

 

Next question. the XML I am outputting depends a lot on the users interaction. What I was thinking to do was based on the Users selection I would use PHP to call the raw XML file. I can then use PHP to insert the correct XSL style sheet (based on the users selection) and then echo that data to the display?

 

how does that sound?

Link to comment
Share on other sites

Next question. the XML I am outputting depends a lot on the users interaction. What I was thinking to do was based on the Users selection I would use PHP to call the raw XML file. I can then use PHP to insert the correct XSL style sheet (based on the users selection) and then echo that data to the display?

 

An XSL is embedded in your XML if they ask for XML(y) then you just readfile the particular XML, the browser knows what to do once it receives it. However what kind of data does this XML hold? What's your assumption of the size this would grow to?

Link to comment
Share on other sites

An XSL is embedded in your XML

Actually the xml does not have the <?xml-stylesheet href="filename.xsl" type="text/xsl"?> info in it when I pull it.

 

So I am going to have the php insert the style sheet info. then echo the XML to the page. I am testing it now.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.