Page 1 of 1

getting XML data using php querystring

Posted: Fri Apr 01, 2011 5:47 pm
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.

Re: getting XML data using php querystring

Posted: Fri Apr 01, 2011 8:34 pm
by fugix
probably want to use simplexml_load_file() or simplexml_load_string()

Re: getting XML data using php querystring

Posted: Sat Apr 02, 2011 4:47 am
by yzgulec
Thanks fugix. Any coding idea ?