kts Posted May 17, 2010 Share Posted May 17, 2010 So I have a dataset that is coming back in the version of XML (although not sure if its older, or just not the standard format) it looks like this: <result> <rows> <row> <column name="osis number">209959568</column> <column name="Last Name">Lee</column> </row> <row> <column name="osis number">264978495</column> <column name="Last Name">Stover</column> </row> <row> <column name="osis number">267274983</column> <column name="Last Name">Cruz</column> </row> <row> <column name="osis number">215475278</column> <column name="Last Name">Henderson</column> </row> <row> <column name="osis number">265384750</column> <column name="Last Name">Christian</column> </row> <row> <column name="osis number">267445849</column> <column name="Last Name">Montes</column> </row> <row> <column name="osis number">267545127</column> <column name="Last Name">Jordan</column> </row> <row> <column name="osis number">214962268</column> <column name="Last Name">Lane</column> </row> <row> <column name="osis number">265608117</column> <column name="Last Name">Rice</column> </row> <row> <column name="osis number">204897672</column> <column name="Last Name">French</column> </row> </rows> </result> I am trying to use existing functions like xml2array, although you can see my XML isn't in standard format of <osis number>204897..etc</osis number> Has anyone had to parse XML that looks like this? Also, is it coming out this way because of the spaces in the names? or is just an older style? Thanks Link to comment https://forums.phpfreaks.com/topic/202047-parsing-xml-from-a-query-with-php/ Share on other sites More sharing options...
Jiin Posted May 17, 2010 Share Posted May 17, 2010 It seems like you are trying to parse xml attributes: <column [b]name="osis number"[/b]>209959568</column> I googled "parsing xml attributes with php" and hit these links: http://paulstamatiou.com/how-to-parse-xml-with-php5 http://www.webmasterworld.com/forum26/326.htm I hope one of those will get you started in the right direction Keep us posted. Link to comment https://forums.phpfreaks.com/topic/202047-parsing-xml-from-a-query-with-php/#findComment-1059540 Share on other sites More sharing options...
kts Posted May 17, 2010 Author Share Posted May 17, 2010 Hey Jiin thanks the first link seems to be the way I need to go! But I am receiving an error with: Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Start tag expected, '<' not found in I have seen it in many ways of attempting this... I believe its due to the format of the XML... Not sure Link to comment https://forums.phpfreaks.com/topic/202047-parsing-xml-from-a-query-with-php/#findComment-1059574 Share on other sites More sharing options...
Jiin Posted May 17, 2010 Share Posted May 17, 2010 You will have to put it in a foreach loop but here is a good start: <?php $xmlfile = simplexml_load_file('t.xml'); $colname = $xmlfile->xpath('/result/rows/row/column/@name'); echo $colname[0]; ?> Link to comment https://forums.phpfreaks.com/topic/202047-parsing-xml-from-a-query-with-php/#findComment-1059630 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.