getting XML data using php querystring

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yzgulec
Forum Newbie
Posts: 2
Joined: Fri Apr 01, 2011 5:17 pm

getting XML data using php querystring

Post by yzgulec »

Hello,

I have an XML file like this:

<?xml version="1.0"?>
<document>
<symptoms>
<symptom>
<type>general</type>
<area>legs</area>
<title>Ankle Pain</title>
<url>/symptoms/symptom-1.html</url>
<contentID>anklePain</contentID>
</symptom>

<symptom>
<type>female</type>
<area>abdomen_pelvis</area>
<title>Bleeding After Menopause</title>
<url>/symptoms/symptom-2.html</url>
<contentID>BleedingAfterMenopause</contentID>
</symptom>

<symptom>
<type>male</type>
<area>abdomen_pelvis</area>
<title>Blood in the Urine in Men</title>
<url>/symptoms/symptom-3.html</url>
<contentID>bloodintheurineinmen</contentID>
</symptom>
</symptoms>
</document>

I would like to have a PHP script that outputs the exact part of XML file when url is written by a query criteria. For example

www.mydomain.com/script.php?type=male&a ... men_pelvis

will output:

<document>
<symptoms>
<symptom>
<type>male</type>
<area>abdomen_pelvis</area>
<title>Blood in the Urine in Men</title>
<url>/symptoms/symptom-3.html</url>
<contentID>bloodintheurineinmen</contentID>
</symptom>
</symptoms>
</document>

and for example if the query criteria is "male": www.mydomain.com/script.php?type=male

the output should contain both general and male tags in xml file ( or if the criteria is "female" it should take "female" and "general" tags):

<document>
<symptoms>
<symptom>
<type>general</type>
<area>legs</area>
<title>Ankle Pain</title>
<url>/symptoms/symptom-1.html</url>
<contentID>anklePain</contentID>
</symptom>

<symptom>
<type>male</type>
<area>abdomen_pelvis</area>
<title>Blood in the Urine in Men</title>
<url>/symptoms/symptom-3.html</url>
<contentID>bloodintheurineinmen</contentID>
</symptom>
</symptoms>
</document>

I am new at PHP, I've tried something but I couldn't get the result I want. I don't know it is a complex problem or not. Can you please help?

Thank you.
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: getting XML data using php querystring

Post by fugix »

probably want to use simplexml_load_file() or simplexml_load_string()
yzgulec
Forum Newbie
Posts: 2
Joined: Fri Apr 01, 2011 5:17 pm

Re: getting XML data using php querystring

Post by yzgulec »

Thanks fugix. Any coding idea ?
Post Reply