ccarlisleiv
asked on
How do I parse XML with PHP not using SimpleXML
So I'm pretty new to both php and xml, but I am trying to get some data into a database from a medical database. Most of the data is easily parsed and I have no problem entering it into the database, but there is one xml field that looks as follows:
<MeshHeadingList>
<MeshHeading>
<DescriptorName MajorTopicYN="N">Animal</D escriptorN ame>
</MeshHeading>
<MeshHeading>
<DescriptorName MajorTopicYN="N">Dogs</Des criptorNam e>
</MeshHeading>
<MeshHeading>
<DescriptorName MajorTopicYN="Y">Myocardia l Contraction</DescriptorNam e>
</MeshHeading>
<MeshHeading>
<DescriptorName MajorTopicYN="N">Myocardiu m</Descrip torName>
<QualifierName MajorTopicYN="Y">metabolis m</Qualifi erName>
</MeshHeading>
<MeshHeading>
<DescriptorName MajorTopicYN="Y">Oxygen Consumption</DescriptorNam e>
</MeshHeading>
<MeshHeading>
<DescriptorName MajorTopicYN="N">Surface Tension</DescriptorName>
</MeshHeading>
</MeshHeadingList>
A lot of different headings, all with attributes. What I have been using so far is:
$rows[$count]->meshid = $results['PubmedArticleSet ']['Pubmed Article'][ $count]['M eshHeading List']['Me shHeading' ]['Descrip torName'];
(changed for each variable I want ), and it works with the previous one-element, non-attributed fields.
What would be an appropriate way to somehow make the results an array that i can store? Is there an easy way to get around the attribute field? I don't need to store the "MajorTopicYN" or the result at all, just the key words.
Any help would be appreciated,
Thanks!
ccarlisleiv
<MeshHeadingList>
<MeshHeading>
<DescriptorName MajorTopicYN="N">Animal</D
</MeshHeading>
<MeshHeading>
<DescriptorName MajorTopicYN="N">Dogs</Des
</MeshHeading>
<MeshHeading>
<DescriptorName MajorTopicYN="Y">Myocardia
</MeshHeading>
<MeshHeading>
<DescriptorName MajorTopicYN="N">Myocardiu
<QualifierName MajorTopicYN="Y">metabolis
</MeshHeading>
<MeshHeading>
<DescriptorName MajorTopicYN="Y">Oxygen Consumption</DescriptorNam
</MeshHeading>
<MeshHeading>
<DescriptorName MajorTopicYN="N">Surface Tension</DescriptorName>
</MeshHeading>
</MeshHeadingList>
A lot of different headings, all with attributes. What I have been using so far is:
$rows[$count]->meshid = $results['PubmedArticleSet
(changed for each variable I want ), and it works with the previous one-element, non-attributed fields.
What would be an appropriate way to somehow make the results an array that i can store? Is there an easy way to get around the attribute field? I don't need to store the "MajorTopicYN" or the result at all, just the key words.
Any help would be appreciated,
Thanks!
ccarlisleiv
What is preventing you from using SimpleXML?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. I realize now that I could of course use SimpleXML, but for some reason I had thought that if I used it I would have to use it for the entire document. Thanks, and this helped a lot.
Thanks for the points! Best of luck with your project, ~Ray