Jump to content

Parsing XML from a Query with PHP


kts

Recommended Posts

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

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  8)

Keep us posted.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.