Jump to content

Search the Community

Showing results for tags 'xpath'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 14 results

  1. When you upload a file I am trying to display it in a HTML table in one column and then transform it into another file in another column automatically so you only need to upload one file instead of two. I can transform it into the same format but I don't know how to convert it to the other format when you have uploaded it. The code below transforms the XML file and displays it into the table once you have uploaded a file. This is a link to the page so you can see what it does. http://projectassignment.esy.es/project%20Assignment/test3.php The other link to the other transformed xml page is this. http://projectassignment.esy.es/project%20Assignment/cgx2.php <?php error_reporting(1); $dom = new DOMDocument('1.0', 'utf-8'); $dom->formatOutput = true; $dom->preserveWhiteSpace = false; $name = $_FILES['file']['name']; $dom->load($name); //$cogxml = simplexml_load_file($name); $extension = strtolower(substr($name, strpos($name, '.') + 1)); #$size = $_FILES['file']['size']; # $type = $_FILES['file']['type']; $tmp_name = $_FILES['file']['tmp_name']; if (isset($name)) { if (!empty($name)) { if (($extension == 'cogxml' || $extension == 'cgx')) { $location = ''; if (move_uploaded_file($tmp_name, $location . $name)) { echo 'uploaded'; } else { echo 'There was an error'; } } else { echo 'File must be cogxml or cgx.'; } } } $newdom = new DOMDocument('1.0', 'utf-8'); $newdom->formatOutput = true; $newdom->preserveWhiteSpace = false; $xpath = new DOMXPath($dom); ?> <html> <head></head> <body> <form action="test3.php" method="POST" enctype="multipart/form-data"> <input type="file" name="file" multiple><br><br> <input type="submit" value="Upload"> </form> <table border=1> <tr><th width='5%'>Concept Name</th><th width='5%'>Relation Type</th><th width='44%'>CoGui XML</th><th width='46%'>CharGer XML</th></tr> <?php foreach ($dom->getElementsByTagName("ctype") as $ctype) { ?> <tr><td> <?php echo $ctype->getAttribute('label') ?></td><td></td> <?php $newdom->loadXML("<cogxml><support><conceptTypes /><relationTypes /></support></cogxml>"); $newnode = $newdom->importNode($ctype, true); $newdom->getElementsByTagName("conceptTypes")->item(0)->appendChild($newnode); $id = $ctype->getAttribute('id'); foreach ($xpath->query("//cogxml/support/conceptTypes/order[@id1='$id']") as $order) { $newnode = $newdom->importNode($order, true); $newdom->getElementsByTagName("conceptTypes")->item(0)->appendChild($newnode); } foreach ($xpath->query("//cogxml/support/relationTypes/rtype[contains(@idSignature, '$id')]") as $rtype) { $newnode = $newdom->importNode($rtype, true); $newdom->getElementsByTagName("relationTypes")->item(0)->appendChild($newnode); } ?> <td><xmp><?php echo $newdom->saveXML(); ?> </xmp></td><td></td></tr><?php } ?> </table> </body> </html> $name is the file you upload. An example file is this. <?xml version="1.0" encoding="UTF-8" standalone="no"?> <cogxml> <namespace name="http://www.lirmm.fr/cogui#" prefix=""/> <support name="vocabulary"> <conceptTypes> <ctype id="http://www.lirmm.fr/cogui#ct_043ea910-5f86-4150-b0f1-1418acf4db39" label="Junior Employee" x="250" y="10"> <translation descr="" label="Junior Employee" lang="en"/> </ctype> <ctype id="http://www.lirmm.fr/cogui#ct_d7a78641-722f-4609-8f5a-90affc111e00" label="Employee" x="130" y="60"> <translation descr="" label="Employee" lang="en"/> </ctype> <ctype id="http://www.lirmm.fr/cogui#ct_feeca670-2f1c-433e-9271-4cffeda1e929" label="Director" x="250" y="110"> <translation descr="" label="Director" lang="en"/> </ctype> <ctype id="http://www.lirmm.fr/cogui#ct_710bed80-a33e-4a13-b916-15fbb3357e8d" label="Manager" x="250" y="60"> <translation descr="" label="Manager" lang="en"/> </ctype> <ctype id="http://www.lirmm.fr/cogui#ct_cd84c648-ef22-4854-8e8c-a6654c0386be" label="Senior Employee" x="255" y="190"> <translation descr="" label="Senior Employee" lang="en"/> </ctype> <ctype id="http://www.lirmm.fr/cogui#_ct_a12bacc5-bc88-429e-a7b1-45e143591288" label="Top" x="10" y="60"> <translation descr="" label="Top" lang="en"/> </ctype> <order id1="http://www.lirmm.fr/cogui#ct_cd84c648-ef22-4854-8e8c-a6654c0386be" id2="http://www.lirmm.fr/cogui#ct_d7a78641-722f-4609-8f5a-90affc111e00"/> <order id1="http://www.lirmm.fr/cogui#ct_feeca670-2f1c-433e-9271-4cffeda1e929" id2="http://www.lirmm.fr/cogui#ct_d7a78641-722f-4609-8f5a-90affc111e00"/> <order id1="http://www.lirmm.fr/cogui#ct_d7a78641-722f-4609-8f5a-90affc111e00" id2="http://www.lirmm.fr/cogui#_ct_a12bacc5-bc88-429e-a7b1-45e143591288"/> <order id1="http://www.lirmm.fr/cogui#ct_043ea910-5f86-4150-b0f1-1418acf4db39" id2="http://www.lirmm.fr/cogui#ct_d7a78641-722f-4609-8f5a-90affc111e00"/> <order id1="http://www.lirmm.fr/cogui#ct_710bed80-a33e-4a13-b916-15fbb3357e8d" id2="http://www.lirmm.fr/cogui#ct_d7a78641-722f-4609-8f5a-90affc111e00"/> </conceptTypes> <relationTypes> <rtype id="http://www.lirmm.fr/cogui#_rt_c42a5ce6-2f20-491d-8c91-501ae178a36c" idSignature="http://www.lirmm.fr/cogui#_ct_a12bacc5-bc88-429e-a7b1-45e143591288 http://www.lirmm.fr/cogui#_ct_a12bacc5-bc88-429e-a7b1-45e143591288" label="Link" x="10.0" y="10.0"> <translation descr="" label="Link" lang="en"/> </rtype> <rtype id="http://www.lirmm.fr/cogui#rt_af40394c-9e62-4e92-b05b-352de5db876f" idSignature="http://www.lirmm.fr/cogui#_ct_a12bacc5-bc88-429e-a7b1-45e143591288 http://www.lirmm.fr/cogui#_ct_a12bacc5-bc88-429e-a7b1-45e143591288" label="senior" x="70.0" y="10.0"> <translation descr="" label="senior" lang="en"/> </rtype> <order id1="http://www.lirmm.fr/cogui#rt_af40394c-9e62-4e92-b05b-352de5db876f" id2="http://www.lirmm.fr/cogui#_rt_c42a5ce6-2f20-491d-8c91-501ae178a36c"/> </relationTypes> <nestingTypes> <ntype id="http://www.lirmm.fr/cogui#_nt_4d626655-02b5-496e-b19c-f4cdb72ee70a" label="Nesting"> <translation descr="" label="Nesting" lang="en"/> </ntype> </nestingTypes> <conformity> <marker id="http://www.lirmm.fr/cogui#i_435d513c-1b39-43b1-9b6d-310fa0ee46d3" idType="http://www.lirmm.fr/cogui#ct_710bed80-a33e-4a13-b916-15fbb3357e8d" label="Lucy"/> <marker id="http://www.lirmm.fr/cogui#i_80311575-7d72-4af7-bdbe-a19c4bbcf248" idType="http://www.lirmm.fr/cogui#ct_cd84c648-ef22-4854-8e8c-a6654c0386be" label="Simon"/> <marker id="http://www.lirmm.fr/cogui#i_d1a8babc-3d35-4580-b4d5-d3cd4c323c98" idType="http://www.lirmm.fr/cogui#ct_043ea910-5f86-4150-b0f1-1418acf4db39" label="Robyn"/> <marker id="http://www.lirmm.fr/cogui#i_efbef15b-d6e2-4c0a-8155-ecaae75cc673" idType="http://www.lirmm.fr/cogui#ct_feeca670-2f1c-433e-9271-4cffeda1e929" label="Richard"/> </conformity> <modules/> </support> <localeTypes name="undefined_vocabulary"> <conceptTypes/> <relationTypes/> <nestingTypes/> <conformity/> <modules/> </localeTypes> <graph id="_g1" label="seniorities" nature="fact" set="default_set"> <concept id="c_f55e1936-7842-4518-b460-bb34a9000871" idMarker="http://www.lirmm.fr/cogui#i_d1a8babc-3d35-4580-b4d5-d3cd4c323c98" idType="http://www.lirmm.fr/cogui#ct_043ea910-5f86-4150-b0f1-1418acf4db39" referent="individual" x="0" y="0"/> <concept id="c_f081c276-57ff-4650-94ec-6e40dfd38023" idMarker="http://www.lirmm.fr/cogui#i_80311575-7d72-4af7-bdbe-a19c4bbcf248" idType="http://www.lirmm.fr/cogui#ct_cd84c648-ef22-4854-8e8c-a6654c0386be" referent="individual" x="185" y="70"/> <concept id="c_f0229ed1-c913-4373-af9c-361a90a56e90" idMarker="http://www.lirmm.fr/cogui#i_435d513c-1b39-43b1-9b6d-310fa0ee46d3" idType="http://www.lirmm.fr/cogui#ct_710bed80-a33e-4a13-b916-15fbb3357e8d" referent="individual" x="330" y="170"/> <concept id="c_dbe5b7cb-7d00-44f1-8b9a-832d5b61a126" idMarker="http://www.lirmm.fr/cogui#i_efbef15b-d6e2-4c0a-8155-ecaae75cc673" idType="http://www.lirmm.fr/cogui#ct_feeca670-2f1c-433e-9271-4cffeda1e929" referent="individual" x="445" y="260"/> <relation id="r_10008dd3-5426-4c87-8651-049045f98376" idType="http://www.lirmm.fr/cogui#rt_af40394c-9e62-4e92-b05b-352de5db876f" x="90" y="70"/> <relation id="r_8ef0b4bf-3cb6-4dde-9c83-903cb459872a" idType="http://www.lirmm.fr/cogui#rt_af40394c-9e62-4e92-b05b-352de5db876f" x="235" y="135"/> <relation id="r_563d1804-04eb-45d4-81c9-f4bd4782e0b1" idType="http://www.lirmm.fr/cogui#rt_af40394c-9e62-4e92-b05b-352de5db876f" x="355" y="260"/> <edge cid="c_f55e1936-7842-4518-b460-bb34a9000871" label="1" rid="r_10008dd3-5426-4c87-8651-049045f98376"/> <edge cid="c_f081c276-57ff-4650-94ec-6e40dfd38023" label="2" rid="r_10008dd3-5426-4c87-8651-049045f98376"/> <edge cid="c_f081c276-57ff-4650-94ec-6e40dfd38023" label="1" rid="r_8ef0b4bf-3cb6-4dde-9c83-903cb459872a"/> <edge cid="c_f0229ed1-c913-4373-af9c-361a90a56e90" label="2" rid="r_8ef0b4bf-3cb6-4dde-9c83-903cb459872a"/> <edge cid="c_f0229ed1-c913-4373-af9c-361a90a56e90" label="1" rid="r_563d1804-04eb-45d4-81c9-f4bd4782e0b1"/> <edge cid="c_dbe5b7cb-7d00-44f1-8b9a-832d5b61a126" label="2" rid="r_563d1804-04eb-45d4-81c9-f4bd4782e0b1"/> </graph> <graph id="_query1" label="Richard senior to Robyn" nature="query" set="default_set"> <concept id="c_90dc1159-1d02-4707-a444-2e95817d8667" idMarker="http://www.lirmm.fr/cogui#i_d1a8babc-3d35-4580-b4d5-d3cd4c323c98" idType="http://www.lirmm.fr/cogui#ct_043ea910-5f86-4150-b0f1-1418acf4db39" referent="individual" x="30" y="165"/> <concept id="c_4af4cf1c-5383-413b-bee2-7a4c513fd37e" idMarker="http://www.lirmm.fr/cogui#i_efbef15b-d6e2-4c0a-8155-ecaae75cc673" idType="http://www.lirmm.fr/cogui#ct_feeca670-2f1c-433e-9271-4cffeda1e929" referent="individual" x="45" y="25"/> <relation id="r_c51c5a9c-3cf5-4402-a356-03c9882f6b78" idType="http://www.lirmm.fr/cogui#rt_af40394c-9e62-4e92-b05b-352de5db876f" x="75" y="95"/> <edge cid="c_90dc1159-1d02-4707-a444-2e95817d8667" label="1" rid="r_c51c5a9c-3cf5-4402-a356-03c9882f6b78"/> <edge cid="c_4af4cf1c-5383-413b-bee2-7a4c513fd37e" label="2" rid="r_c51c5a9c-3cf5-4402-a356-03c9882f6b78"/> </graph> <rule id="_rule1"> <hypt> <graph id="_rule1_hypt" label="seniority rule" nature="rule" set="default_set"> <concept id="c_591883b6-ca82-42ee-bd35-b4ce29ffd286" idType="http://www.lirmm.fr/cogui#ct_d7a78641-722f-4609-8f5a-90affc111e00" x="30" y="45"/> <concept id="c_f765dff9-1cd4-42f1-bf95-87cbda00257d" idType="http://www.lirmm.fr/cogui#ct_d7a78641-722f-4609-8f5a-90affc111e00" x="30" y="173"/> <concept id="c_669f89c9-eb93-4caa-aa90-f8e31be92245" idType="http://www.lirmm.fr/cogui#ct_d7a78641-722f-4609-8f5a-90affc111e00" x="30" y="293"/> <relation id="r_93ecba23-873d-490c-8ce3-40611158006b" idType="http://www.lirmm.fr/cogui#rt_af40394c-9e62-4e92-b05b-352de5db876f" x="45" y="113"/> <relation id="r_257f3815-2ac4-4b9e-8b8c-7d9ae6259b52" idType="http://www.lirmm.fr/cogui#rt_af40394c-9e62-4e92-b05b-352de5db876f" x="53" y="233"/> <edge cid="c_591883b6-ca82-42ee-bd35-b4ce29ffd286" label="1" rid="r_93ecba23-873d-490c-8ce3-40611158006b"/> <edge cid="c_f765dff9-1cd4-42f1-bf95-87cbda00257d" label="2" rid="r_93ecba23-873d-490c-8ce3-40611158006b"/> <edge cid="c_f765dff9-1cd4-42f1-bf95-87cbda00257d" label="1" rid="r_257f3815-2ac4-4b9e-8b8c-7d9ae6259b52"/> <edge cid="c_669f89c9-eb93-4caa-aa90-f8e31be92245" label="2" rid="r_257f3815-2ac4-4b9e-8b8c-7d9ae6259b52"/> </graph> </hypt> <conc> <graph id="_rule1_conc"> <concept id="c_fe469224-c26a-49dc-a17a-697faa20aca3" idType="http://www.lirmm.fr/cogui#ct_d7a78641-722f-4609-8f5a-90affc111e00" x="173" y="53"/> <concept id="c_656473af-5b41-4ed7-b4fc-be3af9ce544d" idType="http://www.lirmm.fr/cogui#ct_d7a78641-722f-4609-8f5a-90affc111e00" x="180" y="293"/> <relation id="r_3b36e657-bc62-4050-baad-c3a04ade3af2" idType="http://www.lirmm.fr/cogui#rt_af40394c-9e62-4e92-b05b-352de5db876f" x="203" y="158"/> <edge cid="c_fe469224-c26a-49dc-a17a-697faa20aca3" label="1" rid="r_3b36e657-bc62-4050-baad-c3a04ade3af2"/> <edge cid="c_656473af-5b41-4ed7-b4fc-be3af9ce544d" label="2" rid="r_3b36e657-bc62-4050-baad-c3a04ade3af2"/> </graph> </conc> <conPts> <couple idC1="c_591883b6-ca82-42ee-bd35-b4ce29ffd286" idC2="c_fe469224-c26a-49dc-a17a-697faa20aca3"/> <couple idC1="c_669f89c9-eb93-4caa-aa90-f8e31be92245" idC2="c_656473af-5b41-4ed7-b4fc-be3af9ce544d"/> </conPts> </rule> </cogxml> The other transformed php file looks like this. <?php error_reporting(1); $dom = new DOMDocument('1.0', 'utf-8'); $dom->formatOutput = true; $dom->preserveWhiteSpace = false; $name = $_FILES['file']['name']; $dom->load($name); $extension = strtolower(substr($name, strpos($name, '.') + 1)); #$size = $_FILES['file']['size']; # $type = $_FILES['file']['type']; $tmp_name = $_FILES['file']['tmp_name']; if (isset($name)) { if (!empty($name)) { if (($extension == 'cogxml' || $extension == 'cgx')) { $location = ''; if (move_uploaded_file($tmp_name, $location . $name)) { echo 'uploaded'; } else { echo 'There was an error'; } } else { echo 'File must be cogxml or cgx.'; } } } $newdom = new DOMDocument('1.0', 'utf-8'); $newdom->formatOutput = true; $newdom->preserveWhiteSpace = false; $xpath = new DOMXPath($dom); ?> <html> <head> <title>Parsing CharGer and CoGui</title> <link rel="stylesheet" type="text/css" href="myStyle.css" /> </head> <body> <form action="cgx2.php" method="POST" enctype="multipart/form-data"> <input type="file" name="file"><br><br> <input type="submit" value="Submit"> </form> <?php echo "<table border=1> <tr><th width='5%'>Concept Name</th><th width='5%'>Relation Type</th><th width='44%'>CoGui XML</th><th width='46%'>CharGer XML</th></tr>"; foreach ($dom->getElementsByTagName("concept") as $concept) { echo '<tr><td></td><td>' . $concept->getAttribute('label') . '</td><td></td>'; $newdom->loadXML("<conceptualgraph><graph><concept /><relation /></graph></conceptualgraph>"); $newnode = $newdom->importNode($concept, true); $newdom->getElementsByTagName("concept")->item(0)->appendChild($newnode); $id = $concept->getAttribute('id'); foreach ($xpath->query("//conceptualgraph/graph/relation[contains(@owner, '$id')]") as $rtype) { $newnode = $newdom->importNode($rtype, true); $newdom->getElementsByTagName("relation")->item(0)->appendChild($newnode); } echo '<td><xmp>' . $newdom->saveXML() . '</xmp></td><td></td></tr>'; } echo '</table>'; ?> </body> </html> An example of the file you upload would be this. <?xml version="1.0" encoding="UTF-8"?> <conceptualgraph editor="CharGer" version="4.1.0" created="Jan 4, 2016 12:06:58 AM" modified="Jan 4, 2016 12:36:07 AM" user="Charli" wrapLabels="false" wrapColumns="30"> <graph id="401e8946:15209f3d481:-7fd9" owner="0"> <type> <label>Proposition</label> </type> <layout> <rectangle x="5.00" y="5.00" width="1200.00" height="900.00"/> <color foreground="0,94,192" background="0,94,192"/> <font name="SansSerif" style="1" size="12" /> </layout> <relation id="401e8946:15209f3d481:-7f98" owner="401e8946:15209f3d481:-7fd9"> <type> <label>Child Of Adult</label> </type> <layout> <rectangle x="341.00" y="114.00" width="40.00" height="24.00"/> <color foreground="0,0,0" background="255,231,100"/> <font name="SansSerif" style="1" size="12" /> </layout> </relation> <relation id="401e8946:15209f3d481:-7fcc" owner="401e8946:15209f3d481:-7fd9"> <type> <label>Parent Of Child</label> </type> <layout> <rectangle x="172.00" y="70.00" width="40.00" height="24.00"/> <color foreground="0,0,0" background="255,231,100"/> <font name="SansSerif" style="1" size="12" /> </layout> </relation> <relation id="401e8946:15209f3d481:-7faa" owner="401e8946:15209f3d481:-7fd9"> <type> <label>Mother Of Child</label> </type> <layout> <rectangle x="317.00" y="310.00" width="40.00" height="24.00"/> <color foreground="0,0,0" background="255,231,100"/> <font name="SansSerif" style="1" size="12" /> </layout> </relation> <relation id="401e8946:15209f3d481:-7fa0" owner="401e8946:15209f3d481:-7fd9"> <type> <label>Gender Of Child</label> </type> <layout> <rectangle x="278.00" y="270.00" width="40.00" height="24.00"/> <color foreground="0,0,0" background="255,231,100"/> <font name="SansSerif" style="1" size="12" /> </layout> </relation> <relation id="401e8946:15209f3d481:-7fc5" owner="401e8946:15209f3d481:-7fd9"> <type> <label>Gender of Adult</label> </type> <layout> <rectangle x="79.00" y="218.00" width="40.00" height="24.00"/> <color foreground="0,0,0" background="255,231,100"/> <font name="SansSerif" style="1" size="12" /> </layout> </relation> <concept id="401e8946:15209f3d481:-7fd4" owner="401e8946:15209f3d481:-7fd9"> <type> <label>Girl</label> </type> <layout> <rectangle x="92.00" y="298.00" width="40.00" height="30.00"/> <color foreground="255,255,255" background="0,94,192"/> <font name="SansSerif" style="1" size="12" /> </layout> </concept> <concept id="401e8946:15209f3d481:-7fd5" owner="401e8946:15209f3d481:-7fd9"> <type> <label>Female</label> </type> <layout> <rectangle x="358.50" y="201.00" width="49.00" height="30.00"/> <color foreground="255,255,255" background="0,94,192"/> <font name="SansSerif" style="1" size="12" /> </layout> </concept> <concept id="401e8946:15209f3d481:-7fb3" owner="401e8946:15209f3d481:-7fd9"> <type> <label>Woman</label> </type> <layout> <rectangle x="148.00" y="262.00" width="52.00" height="30.00"/> <color foreground="255,255,255" background="0,94,192"/> <font name="SansSerif" style="1" size="12" /> </layout> </concept> <concept id="401e8946:15209f3d481:-7fd6" owner="401e8946:15209f3d481:-7fd9"> <type> <label>Adult</label> </type> <layout> <rectangle x="162.00" y="129.00" width="40.00" height="30.00"/> <color foreground="255,255,255" background="0,94,192"/> <font name="SansSerif" style="1" size="12" /> </layout> </concept> <concept id="401e8946:15209f3d481:-7fd7" owner="401e8946:15209f3d481:-7fd9"> <type> <label>Child</label> </type> <layout> <rectangle x="37.00" y="148.00" width="40.00" height="30.00"/> <color foreground="255,255,255" background="0,94,192"/> <font name="SansSerif" style="1" size="12" /> </layout> </concept> <concept id="401e8946:15209f3d481:-7fd8" owner="401e8946:15209f3d481:-7fd9"> <type> <label>Human</label> </type> <layout> <rectangle x="181.00" y="11.00" width="48.00" height="30.00"/> <color foreground="255,255,255" background="0,94,192"/> <font name="SansSerif" style="1" size="12" /> </layout> </concept> <arrow id="401e8946:15209f3d481:-7f96" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7f98" to="401e8946:15209f3d481:-7fbb"> <layout> <rectangle x="396.48" y="128.66" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7fca" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7fcc" to="401e8946:15209f3d481:-7fd8"> <layout> <rectangle x="193.77" y="53.12" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7f97" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7f9b" to="401e8946:15209f3d481:-7f98"> <layout> <rectangle x="314.23" y="169.88" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7fcb" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7fd6" to="401e8946:15209f3d481:-7fcc"> <layout> <rectangle x="183.48" y="106.05" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7f99" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7f9c" to="401e8946:15209f3d481:-7fd6"> <layout> <rectangle x="207.00" y="160.54" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7fab" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7fb0" to="401e8946:15209f3d481:-7fd8"> <layout> <rectangle x="274.59" y="47.60" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7fac" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7fbb" to="401e8946:15209f3d481:-7fb0"> <layout> <rectangle x="384.85" y="99.96" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7fad" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7fb2" to="401e8946:15209f3d481:-7fd8"> <layout> <rectangle x="235.08" y="53.19" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7fae" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7fd5" to="401e8946:15209f3d481:-7fb2"> <layout> <rectangle x="316.05" y="140.06" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7fc2" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7fc5" to="401e8946:15209f3d481:-7fd7"> <layout> <rectangle x="76.19" y="195.99" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7fc3" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7fd4" to="401e8946:15209f3d481:-7fc5"> <layout> <rectangle x="101.07" y="264.73" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7fa1" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7fa3" to="401e8946:15209f3d481:-7fd6"> <layout> <rectangle x="165.23" y="172.76" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7fa2" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7fb3" to="401e8946:15209f3d481:-7fa3"> <layout> <rectangle x="161.91" y="233.11" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7fa4" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7fa7" to="401e8946:15209f3d481:-7fbb"> <layout> <rectangle x="414.30" y="251.12" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7fc7" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7fc9" to="401e8946:15209f3d481:-7fd6"> <layout> <rectangle x="140.08" y="113.96" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7fa5" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7fc1" to="401e8946:15209f3d481:-7fa7"> <layout> <rectangle x="224.84" y="350.58" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7fc8" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7fd7" to="401e8946:15209f3d481:-7fc9"> <layout> <rectangle x="85.27" y="122.84" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7fa8" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7faa" to="401e8946:15209f3d481:-7fd5"> <layout> <rectangle x="354.68" y="268.04" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7fa9" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7fd4" to="401e8946:15209f3d481:-7faa"> <layout> <rectangle x="222.14" y="313.57" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7fbc" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7fbf" to="401e8946:15209f3d481:-7fd7"> <layout> <rectangle x="49.28" y="211.56" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7fbd" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7fc1" to="401e8946:15209f3d481:-7fbf"> <layout> <rectangle x="51.13" y="296.73" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7f9a" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7f9b" to="401e8946:15209f3d481:-7f9c"> <layout> <rectangle x="242.69" y="195.83" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7f9d" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7fa0" to="401e8946:15209f3d481:-7fd5"> <layout> <rectangle x="330.90" y="249.35" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7f9e" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7fb3" to="401e8946:15209f3d481:-7fa0"> <layout> <rectangle x="236.58" y="275.68" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7fb4" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7fb7" to="401e8946:15209f3d481:-7fd8"> <layout> <rectangle x="131.39" y="43.42" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> <arrow id="401e8946:15209f3d481:-7fb5" owner="401e8946:15209f3d481:-7fd9" label="-" from="401e8946:15209f3d481:-7fd7" to="401e8946:15209f3d481:-7fb7"> <layout> <rectangle x="62.59" y="107.31" width="8.00" height="8.00"/> <color foreground="0,0,0" background="255,255,255"/> <font name="SansSerif" style="1" size="12" /> <edge arrowHeadWidth="5" arrowHeadHeight="5" edgeThickness="1.5" /> </layout> </arrow> </graph> </conceptualgraph>
  2. I have the following xml file called -> test.xml <?xml version="1.0"?> <OrderCollection xmlns:xsd="http://www.org/2009/XMLSchema" xmlns:xsi="http://www.w3.org/2009/XMLSchema-instance"> <Orders> <Order Id="130" Model=" Optimized" CampaignName="Promo" OrderName="1074" CreationDate="2013-05-29T16:30:03.41" StartDate="2013-06-03T04:00:00" EndDate="2014-04-22T03:59:59.997" OrderStatus="Active"> <Client Id="5" ExternalId="5" Name="CNL" /> <Lines> <Line Id="699" Status="Canceled" EstimatedReach="0" Desired="1000" Actual="370" MaxViewings="0" Separation="0"> <Line Id="700" Status="Canceled" EstimatedReach="10830" Desired="1000" Actual="0" MaxViewings="0" Separation="0"> <Line Id="701" Status="Canceled" EstimatedReach="0" Desired="1000" Actual="0" MaxViewings="0" Separation="0"> <Line Id="714" Status="Canceled" EstimatedReach="10830" Desired="1000" Actual="1478410" MaxViewings="0" Separation="0"> <Line Id="908" Status="Active" EstimatedReach="0" Desired="1000" Actual="1520" MaxViewings="0" Separation="0"> <Line Id="916" Status="Canceled" EstimatedReach="0" Desired="1000" Actuals="5260" MaxViewings="0" Separation="0"> </Lines> </Order> </Orders> </OrderCollection> For each <Line> node with a entry that has a status attribute of (Status="Active") I need to list The corresponding ID number. So from the XML above I need to pull out only Line Id="908", since it is the only one with a Status equal to Active. I have so far wrote this PHP code to attempt to accomplish this task. <?php $url = 'test.xml'; $xml = simplexml_load_file($url); foreach ($xml->xpath("//Line/@Status") as $t) { echo $t . PHP_EOL; } ?> The above code will print out all the "Status" attribute values properly from each xml LINE node, but I do not know how to put in a check on the xpath command to see if the @Status is set to active and then echo out, only the corresponding Id attribute (i.e 908 in this case) Any help would be greatly appreciated. Thanks,
  3. I want to extract current data from a particular website(http://www.ncdex.com/MarketData/LiveFuturesQuotes.aspx) and then show it on my website. I want to extract only if the Data is "Chana" or else move to next line or stop. Because the website keeps on updating and the field(Chana) always changes its rows. Please help me. <html> <body> <?php $html = file_get_contents('http://www.ncdex.com/MarketData/LiveFuturesQuotes.aspx'); //get the html returned from the following url libxml_use_internal_errors( true); $doc = new DOMDocument; $doc->loadHTML( $html); $xpath = new DOMXpath( $doc); $node4a = $xpath->query( '//*[@id="ctl00_ContentPlaceHolder3_dgLiveFuturesQuotes"]/tbody/tr[11]/td[1]/a')->item( 0); $node4b = $xpath->query( '//*[@id="ctl00_ContentPlaceHolder3_dgLiveFuturesQuotes"]/tbody/tr[11]/td[7]')->item( 0); $node4c = $xpath->query( '//*[@id="ctl00_ContentPlaceHolder3_dgLiveFuturesQuotes"]/tbody/tr[11]/td[8]')->item( 0); $src4 = $xpath->query( '//*[@id="ctl00_ContentPlaceHolder3_dgLiveFuturesQuotes"]/tbody/tr[11]/td[7]/img/@src')->item( 0); $node4d = $xpath->query( '//*[@id="ctl00_ContentPlaceHolder3_dgLiveFuturesQuotes"]/tbody/tr[11]/td[2]')->item( 0); echo $node4a->textContent; // This will print **Chana** echo $node4b->textContent; echo $node4c->textContent; echo $img1; echo $src4->nodeValue; echo $img2; echo "|"; echo $node4d->textContent; echo "<br>"; ?> </html>
  4. How do I know which query hits my HTML DOM? Or how can I separate the results to each query? $xpath = new DomXPath($dom); $nodes = $xpath->query("//tr/td/div[@class='category']/a[1]/text() | //tr/td[@id='data']/div[@class='category_data']/text() | //tr/td[@id='data']/div[@class='category']/text() | //tr/td[@id='data']/div[@class='category']/span[@class='category_data']/text()"); header("Content-type: text/plain"); foreach ($nodes as $i => $node) { if ( ) // Query 1: //tr/td/div[@class='category']/a[1]/text() { output the content here } if ( ) // Query 2: //tr/td[@id='data']/div[@class='category_data']/text() ... and so on echo "Node($i): " . ltrim(rtrim($node->nodeValue)) . "<br> --> " . $node->nodeName . "\n"; } $node->nodeName seems to be wrong. I also tried other option from PHP.net but maybe it isn't possible.
  5. I am working on a project where keywords (submitted from a website) will query a large XML document for matching criteria (for shopping products), then retrieve and return all the relevant search results (much like Google Shopping). There may be 100’s of search results returned, with 20 search results per page. Using PHP for the API call, would XPATH or SAX be better with regard to page loading speed and memory efficiency.
  6. So I'm stuck on an issue while parsing a forum, I want to ignore the quotes and only read the message from the posted user. So .. Imagine I have this HTML loaded. <div class="main"> <div class="quote"> Some stuff written here .. </div> More written here and a <b>bold word</b> or two. </div>So, what I want to return is: More written here and a bold word or two.Which is returned when I evaluate the path, but it also returns what's in the quote and I ain't sure how to ignore that. Using /text() will ignore the bolded words in this example. Thanks for any help.
  7. I need some help to understand the validation of xPath expression in PHP. I want to validate if a xPath expression is correct before i pass it to DOMXPath::query.
  8. I would like to get Type, Id and Height values in database table. It is not working. There is no error message. XML File: <?xml version="1.0" encoding="utf-8"?> <Physical> <Catalog> <EquipmentSpec> <Reference>030_17</Reference> <Type>Duplexeur</Type> <Characteristic><CharacteristicName>Tilt</CharacteristicName> <CharacteristicValue>0</CharacteristicValue></Characteristic> </EquipmentSpec> <EquipmentSpec> <Reference>030_19</Reference> <Type>Node</Type> <Characteristic><CharacteristicName>Tilt</CharacteristicName> <CharacteristicValue>0</CharacteristicValue></Characteristic> </EquipmentSpec> </Catalog> <Installed> <Equipment> <Id>26</Id><Reference>MAT_4</Reference> <Characteristic><CharacteristicName>Height</CharacteristicName><CharacteristicValue>160</CharacteristicValue></Characteristic> </Equipment> <Equipment> <Id>27</Id><Reference>MAT_6890</Reference> <Characteristic><CharacteristicName>Height</CharacteristicName><CharacteristicValue>180</CharacteristicValue></Characteristic> </Equipment> </Installed> </Physical> CODE: foreach ($xml->xpath('Physical') as $spec) { foreach ($spec->xpath('//EquipmentSpec') as $sub) { $Type = $sub->Type; } foreach ($spec->xpath('//Equipment') as $eq) { $Id = $eq->Id; foreach ($eq->Characteristic as $c) { if ($c->CharacteristicName == 'Height') { $Height = $c->CharacteristicValue; } } } $sql = "INSERT INTO machines (`Type`,`Id`,`Height`) VALUES ('".$Type."','".$Id."','".$Height."')"; $req = new requete($site->db, $sql); echo $sql; }
  9. Hello All, I would like to get all Equipment values. I have used DOM Document. It is reading ONLY LAST Element. Equipment Id: 28. I need all three. Thanks in advanced. XML File: <?xml version="1.0" encoding="UTF-8"?> -<Physical> <Catalog> </Catalog> -<Installed> -<Equipment> <Id>26</Id> <Ref>Tew12</Ref> -<Characteristic> <CharacteristicName>Height</CharacteristicName> <CharacteristicValue>160</CharacteristicValue> </Characteristic> -<Characteristic> <CharacteristicName>Tilt</CharacteristicName> <CharacteristicValue>30</CharacteristicValue> </Equipment> -<Equipment> <Id>27</Id> <Ref>Tew13</Ref> -<Characteristic> <CharacteristicName>Height</CharacteristicName> <CharacteristicValue>165</CharacteristicValue> </Characteristic> -<Characteristic> <CharacteristicName>Tilt</CharacteristicName> <CharacteristicValue>50</CharacteristicValue> </Equipment> -<Equipment> <Id>28</Id> <Ref>Tew14</Ref> -<Characteristic> <CharacteristicName>Height</CharacteristicName> <CharacteristicValue>190</CharacteristicValue> </Characteristic> -<Characteristic> <CharacteristicName>Tilt</CharacteristicName> <CharacteristicValue>50</CharacteristicValue> </Equipment> </Installed> </Physical> Expected Result: Id 26 Tilt 30 Id 27 Tilt 50 Id 28 Tilt 50 For the moment, i am trying to get all Ids values. Still it is not giving ALL Ids. It should give Ids: 26 27 28 $Equipments = $dom->getElementsByTagName('Equipment'); foreach( $Equipments as $Equipments ) { $Ids = $Equipments->getElementsByTagName( 'Id' ); $Id = $Ids->item(0)->nodeValue; echo $Id; }
  10. XPATH method for retuning multiple dynamic results from a XML file using PHP I have a form that the user types or selects a value the form is as follows <form id="search_photos" action="photo_result.php" method="get"> <input value="" name="photographer_id" id="photographer_id" style=" border:1px solid Silver;" type="text"> <select name="Photographer" id="Photographer" style="height:23px; border:1px solid Silver;"> <option selected="selected" value="x">Any Photographer</option> <option value="John">John</option> <option value="Fred">Fred</option> <option value="Joseph">Joseph</option> </select> <select name="images" id="images" style="height:23px; border:1px solid Silver;"> <option selected="selected" value="x">All Images</option> <option value="0">None</option> <option value="a">Image a</option> <option value="b">Image b </option> <option value="c">Image c </option> </select> <input name="Submit" value="Search Now >" id="Submit" class="Adv1_Filter_Button" type="submit"> </form> Then the search_photo.php script that catches the result of the form and filters the values entered by the user as follows <?php $xml = simplexml_load_file("photo.xml"); for ($i = 0; $i < count($xml); $i++){ if(isset($_GET["LocationName"])) { $photographer_id = $_GET["LocationName"]; } $result = $xml->xpath('/root/area[photographer_id=' . $photographer_id . '] '); } if(isset($_GET["Photographer"])) { $photographer = $_GET["Photographer"]; } $result = $xml->xpath('/root/area[photographer_id=' . $photographer_id . '] '); if(isset($_GET["images"])) { $image = $_GET["images"]; } echo $photographer_id; echo $photographer; echo $image; var_dump ($result); ?> The $result from the first XPATH pass is correct if all that is set is ‘photographer_id’ if I then try $result=$xml->xpath ('/root/area[photographer_id=' . $photographer_id . '] | /root/area[photographer=' . $photographer .']'); and select 1 and fred then I get the result of an array of all four when it should be an empty array I have trie & (and) insted of | (or) but just returns an empty array should I convert the $result to an object or is the a way of saving the $result to an xml file
  11. I'm trying to pick out items from an XML file by their titles using Xpath in DOM, but because some have apostrophes, and others have quotes, it doesn't work. I've tried replacing the apostrophes using this $query1 = 'channel/item[title='.$p.']/title'; but it only works for the apostrophes, not the quotes. Any advice on how to do this? <?php $q = $_GET["q"]; $q = explode('|^', $q); $counts = count($q); unset($q[$counts-1]); $p = stripslashes($q); $q = stripslashes($p); $dom = new DOMDocument; $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->Load("../$userid.xml"); $xpath = new DOMXPath($dom); foreach ($q as $r) { $p = preg_replace("/'/","",$r); $query1 = "channel/item[title="'.$p.']/title"; $query2 = "channel/item[title="'.$p.']/url"; $query3 = "channel/item[title="'.$p.']"; $entries = $xpath->query($query1); $entries2 = $xpath->query($query2); $entries3 = $xpath->query($query3); foreach ($entries as $entry) { foreach ($entries2 as $entry2) { foreach ($entries3 as $entry3) { $oldchapter = $entry->parentNode->removeChild($entry); $oldchapter2 = $entry2->parentNode->removeChild($entry2); $oldchapter3 = $entry3->parentNode->removeChild($entry3); $dom->preserveWhiteSpace = false; } } } } $dom->formatOutput = true; $dom->save("../$userid.xml") ?> Basically, my code extracts titles from a URL, separated by "|^" (For example title1|^title2|^title3|^). Because the "|^" is appended to the end of each title, I have to remove the empty value from the array. Then, because the titles with apostrophes come in like "Title\\'s", I have to strip slashes twice to get rid of them. Then I load a new DOMdocument, and find the titles from the URL in my existing XML document. Then I want the code to remove the whole items (titles, urls and the item itself) which have the same titles as the ones in the URL, and then save the document.
  12. Basically, I am writing a script in PHP, which can take YouTube videos from playlists, items from RSS feeds and podcasts, and individual YouTube videos and files, and places them into an XML document, so they can browsed and kept in one place. I also have a script which removes these items, if the user wants. The problem I'm facing is with characters. Because I can't control what the user will name their videos/files, or how they're named in the feed, the titles could have quotes, brackets, ampersands, hashes etc, which causes problems when they're being removed and Because I'm using Xpath (which can be temperamental at the best of times) in the remove script, any items with titles with these characters won't get removed. Here's my remove code: <?php $q = $_GET["q"]; $q = stripslashes($q); $q = explode('|^', $q); $counts = count($q); unset($q[$counts-1]); $dom = new DOMDocument; $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->Load("../$userid.xml"); $xpath = new DOMXPath($dom); foreach ($q as $r) { $r = preg_replace("|&|", '&', $r); $r = preg_replace('|"|', '"', $r); $query1 = 'channel/item[title='.$r.']/title'; $query2 = 'channel/item[title='.$r.']/media:content'; $query3 = 'channel/item[title='.$r.']'; $entries = $xpath->query($query1); $entries2 = $xpath->query($query2); $entries3 = $xpath->query($query3); foreach ($entries as $entry) { foreach ($entries2 as $entry2) { foreach ($entries3 as $entry3) { $oldchapter = $entry->parentNode->removeChild($entry); $oldchapter2 = $entry2->parentNode->removeChild($entry2); $oldchapter3 = $entry3->parentNode->removeChild($entry3); $dom->preserveWhiteSpace = false; } } } } $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->save("../$userid.xml") ?> How it works is when the user selects the items they want to remove, using a select box, the selections are put into the URL. My code extracts the titles from the URL, separated by "|^" (For example title1|^title2|^title3|^). Because the "|^" is appended to the end of each title, I have to remove the empty value from the array. Then I load a new DOMdocument, and find the titles from the URL in my existing XML document. Then I want the code to remove the whole items (titles, urls and the item itself) which have the same titles as the ones in the URL, and then save the document, but because some of the titles could have &, ", * or #, they don't get removed. Is there a way that I can maybe screen, and change the characters to get it to work (I tried this with "preg_replace", but it didn't work), or even change them before they're saved to the XML in the first place? Any advice?
  13. I'm trying to pick out items from an XML file by their titles using Xpath in DOM, but because some have apostrophes, it doesn't work. I've tried replacing the apostrophes using this $query1 = "channel/item[title=$p]/title"; but even that doesn't work. Any advice on how to do this, or alternatives for how to extract elements by their titles in DOM? Here's my code: <?php $q = $_GET["q"]; $q = explode('|^', $q); $counts = count($q); unset($q[$counts-1]); $p = stripslashes($q); $q = stripslashes($p); $dom = new DOMDocument; $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->Load("../$userid.xml"); $xpath = new DOMXPath($dom); foreach ($q as $r) { $p = preg_replace("/'/","",$r); $query1 = "channel/item[title=$p]/title"; $query2 = "channel/item[title=$p]/url"; $query3 = "channel/item[title=$p]"; $entries = $xpath->query($query1); $entries2 = $xpath->query($query2); $entries3 = $xpath->query($query3); foreach ($entries as $entry) { foreach ($entries2 as $entry2) { foreach ($entries3 as $entry3) { $oldchapter = $entry->parentNode->removeChild($entry); $oldchapter2 = $entry2->parentNode->removeChild($entry2); $oldchapter3 = $entry3->parentNode->removeChild($entry3); $dom->preserveWhiteSpace = false; } } } } $dom->formatOutput = true; $dom->save("../$userid.xml") ?> Basically, my code extracts titles from a URL, separated by "|^" (For example title1|^title2|^title3|^). Because the "|^" is appended to the end of each title, I have to remove the empty value from the array. Then, because the titles with apostrophes come in like "Title\\'s", I have to strip slashes twice to get rid of them. Then I load a new DOMdocument, and find the titles from the URL in my existing XML document. Then I want the code to remove the whole items (titles, urls and the item itself) which have the same titles as the ones in the URL, and then save the document.
  14. Hi, I have been searching all over the web but have not found a useful answer... Hope you guys can help me. This is the situation. I have a rather big XML file (13Mb - 4100 lines) where I need to search for data in the text elements using regex patterns. To do so, I parse the file with XMLReader (http://www.php.net/XMLReader). I have tried to use DOMDocument (http://www.php.net/m...domdocument.php), which I prefer, but it really is too slow. The script runs really well as it returns me all the matches without any issue and very very fast. BUT, I need to know the exact Xpath of every matched node and, surprisingly, XMLReader does not come with a XPath attribute or metod. So, basically, what I am searching for is a effective (speed is important) way to get to know the XPath of any node parsed with XMLReader... Any suggestions ? Thanks for your time and feedback.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.