Link to home
Start Free TrialLog in
Avatar of ccarlisleiv
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</DescriptorName>
    </MeshHeading>
    <MeshHeading>
        <DescriptorName MajorTopicYN="N">Dogs</DescriptorName>
    </MeshHeading>
    <MeshHeading>
        <DescriptorName MajorTopicYN="Y">Myocardial Contraction</DescriptorName>
    </MeshHeading>
    <MeshHeading>
        <DescriptorName MajorTopicYN="N">Myocardium</DescriptorName>
        <QualifierName MajorTopicYN="Y">metabolism</QualifierName>
    </MeshHeading>
    <MeshHeading>
        <DescriptorName MajorTopicYN="Y">Oxygen Consumption</DescriptorName>
    </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']['PubmedArticle'][$count]['MeshHeadingList']['MeshHeading']['DescriptorName'];

(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

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

What is preventing you from using SimpleXML?
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ccarlisleiv
ccarlisleiv

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