denoteone Posted November 16, 2010 Share Posted November 16, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/218889-parse-xml-directly-to-page-vs-into-an-array/ Share on other sites More sharing options...
ManiacDan Posted November 16, 2010 Share Posted November 16, 2010 An XML document with an XSLT style sheet will be formatted into an HTML document automatically without you using a programming language at all. Quote Link to comment https://forums.phpfreaks.com/topic/218889-parse-xml-directly-to-page-vs-into-an-array/#findComment-1135204 Share on other sites More sharing options...
denoteone Posted November 16, 2010 Author Share Posted November 16, 2010 well I am going to apply css styles and format the data to fit into a html layout that I built. I should have mentioned that. Quote Link to comment https://forums.phpfreaks.com/topic/218889-parse-xml-directly-to-page-vs-into-an-array/#findComment-1135206 Share on other sites More sharing options...
Maq Posted November 16, 2010 Share Posted November 16, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/218889-parse-xml-directly-to-page-vs-into-an-array/#findComment-1135232 Share on other sites More sharing options...
denoteone Posted November 17, 2010 Author Share Posted November 17, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/218889-parse-xml-directly-to-page-vs-into-an-array/#findComment-1135548 Share on other sites More sharing options...
ignace Posted November 17, 2010 Share Posted November 17, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/218889-parse-xml-directly-to-page-vs-into-an-array/#findComment-1135677 Share on other sites More sharing options...
denoteone Posted November 22, 2010 Author Share Posted November 22, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/218889-parse-xml-directly-to-page-vs-into-an-array/#findComment-1137740 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.