I am working in XPATH using PHP. I have done it by hard coded. but I made a lot of googling for making xpath queries dynamic. Is there any solution for making xpath queries dynamic?
I have the following xml code:
<information>
<field name="secondtitle">ABCt</field>
<field name="author">XYZ</field>
<field name="ISBN">9780712617611</field>
<field name="publisher">abc</field>
</information>
the other file's data is in the following:
<information>
<field name="deliveryCosts">1.95</field>
<field name="deliveryTime">3 - 5 Werkdagen</field>
<field name="EAN">9789021142523</field>
<field name="ISBN">9789021142539</field>
<field name="subcategories">abc</field>
<field name="auteur">IJK</field>
<field name="type">xyz</field>
</information>
only the attributes are differ now m trying to access them in a single php file. but all of my queries are hard coded but i want to access them dynamically.
following is my php code that i made hard coded:
$auth = $xml->xpath("/products/product[$i]/additional/field[@name='auteur']");
$type = $xml->xpath("/products/product[$i]/additional/field[@name='type']");
foreach($auth as $au)
{
foreach($type as $ty)
{
echo $au = mysql_real_escape_string($au);
echo $ty = mysql_real_escape_string($ty);
}}
This code is in working with the second code of xml that I have paste above.