Jump to content

Search the Community

Showing results for tags 'domdocument'.

  • 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 6 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. Hi folks, I'm trying to access the elements in the following page: http://www.vopmart.com/pa1013129.html I'm looking to access the div class="main" element and then retrieve each of the elements within this. I;ve completed similar tasks to this in the past but I just can't seem to retrieve anything from this. Any help would be greatly appreciated. My code is //looping variable $i = 0; while ($i <= count($product_link_list)) { //loop through each of the product details pages and scrape data { $html = new DOMDocument(); //Load DOM of individual product page $html->loadHTMLFile($product_link_list[$i]); foreach($html->find('div.main')as $node) { // Find all images foreach ($node->find('img') as $element) { echo $element->src . '<br>'; } // Find all links foreach ($node->find('a') as $element) { echo $element->href . '<br>'; } //looping variable $j = 0; }
  3. Hey guys i need help with a CURL code. I need to retreive all the data in a table located at http://www.listenlive.nl/tvgenre.php?g=1&page=0 and parse the data to finish with an array that looks like this: $row[0][station_name] = '3BTV'; $row[0][stream_link] = '420'; $row[0][stream_type] = 'wma'; $row[0][country] = 'United Kingdom'; $row[0][genre][0] = 'Variety'; $row[0][genre][1] = 'Alternative'; $row[0][genre][2] = 'Culture'; $row[0][rating] = '1/5'; I need that for each rows of the table where the first array number would increment $row[1], $row[2] ... My PHP code is incomplete. I currently have a loop for all the TR's of the page ... and when i loop all the TD's inside the TR's it returns a load of crap ... I am unsure where to go from here. Any help would be apreciated thx This is my code: $ch = curl_init(); $categ[url] = 'http://www.listenlive.nl/tvgenre.php?g=1&page=0'; curl_setopt($ch, CURLOPT_URL, $categ[url]); curl_setopt($ch, CURLOPT_POST, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies); curl_setopt($ch, CURLOPT_COOKIE, $cookies); curl_setopt($ch, CURLOPT_REFERER, $categ[url]); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_USERAGENT, $nav); $data2 = curl_exec($ch); $dom2 = new DOMDocument(); libxml_use_internal_errors(true); $dom2->loadHTML($data2); $trs = $dom2->getElementsByTagName('tr'); foreach ($trs as $tr) { echo "<pre>"; print_r($tr); echo "</pre>"; }
  4. I built a custom templating class that uses DOMDocument to manipulate some of the nodes/tags within my html. I run into all kinds of problems when I use inline js (js that lives on page) Most notably with < and & used in the js itself. This code exibits some of the problems: $domStr = ' <!DOCTYPE html> <head> <meta charset="utf-8"/> <title>my page</title> <script> var elem = "<div>some content</div>"; </script> </head> <body> <div> MY PAGE </div> </body> </html> '; $doc = new DOMDocument(); libxml_use_internal_errors(true);//prevents tags in js from throwing errors; see php.net manual $doc->formatOutput = true; $doc->strictErrorChecking = false; $doc->preserveWhiteSpace = true; $doc->loadHTML($domStr); echo $doc->saveHTML(); exit; and the html output is: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>my page</title> <script> var elem = "<div>some content"; </script> </head> <body> <div> MY PAGE </div> </body> </html> You'll notice that the closing </div> tag is removed. ??? I have very dissapointed with domdocument overall as it doesn't seem to always do what it promises to do...even with preserving space/formatting etc. I'm to the point at which I might just abandon domdocument altogether and parst the html myself with regex (yuck) any expert advice in this matter would be greatly appretiated.
  5. 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; }
  6. Wondering if anyone can help - I'm not entirely sure I'm getting this right. Actually, I know I'm, because it ain't working! I've retrieved a set of pages using cURL, all working fine, and then using a foreach loop to process each page which will either have one main image, or a main image and thumbnails. I've been scratching my head for many hours trying to figure out the logic to get either the thumbnails (and then I can retrieve the bigger images) or just the one big image. Here's the part of the loop: if($node->nodeName == 'div' && $node->getAttribute('id') == 'bigImageWindow' && $node->getAttribute('class') == 'hasThumbnails') { // We have more than 1 image, so use the thumbs approach //echo "a:<br />"; $setImageSrc = "a"; } elseif($node->nodeName == 'ul' && $node->getattribute('id') == 'thumbPage0') { //echo "b:<br />"; $setImageSrc = "b"; } if($setImageSrc == 'a') { if($node->nodeName == 'img' && $node->getAttribute('id') == 'largeImage') { $instr_images[] = $node->getAttribute('src'); } } else { if($node->nodeName == 'ul' && $node->getAttribute('id') == 'thumbPage0') { $vnodes = $node->childNodes; foreach($vnodes as $vnode) { if($vnode->nodeName == 'li') { $wnodes = $vnode->childNodes; foreach($wnodes as $wnode) { if($wnode->nodeName == 'a'){ $xnodes = $wnode->childNodes; foreach($xnodes as $xnode){ if($xnode->nodeName == 'img'){ $instr_images[] = $xnode->getAttribute('src'); } } } } } } } } I know it's a bit long-winded, but the idea is simple. If the page has thumbnails, use those, else, just grab the main image. As you can see from the latest attempt, I'm trying to set a $setImageSrc to process either option a or option b. At best, I've managed to get all the images, but a duplicated first image - this is due to it reading both the big image AND thumbnails - despite the logic that it should be doing either/or... Any ideas?
×
×
  • 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.