The following code produces the XML file that I am after. $dom = new DOMDocument('1.0', 'UTF-8'); // pretty formatting $dom->formatOutput = true; // create root element $root = $dom->createElement('Poem'); $root->setAttribute('object_id', '542'); $dom->appendChild($root); // create title element $title = $dom->createElement('title'); $root->appendChild($title); // create a node for the title element $text = $dom->createTextNode('The Unknown Poem'); $title->appendChild($text); // save xml as string $test = $dom->saveXML(); echo($test); $dom->save('testDOM.xml'); I get `testDom.xml` contaning the details that I need. However, the `echo($test);` prints nothing. What might be the cause I wonder? I tried `print_r()` too. Any suggestions? ## Additional Information ## XAMPP (on Win 8) is …

Member Avatar
Member Avatar
+0 forum 4

Hello everyone, I am trying to retrieve some info from a remote site using PHP DOMDocument and I cannot figure out why the code returns NULL, although the provided ID exists on the page. Please help. $dom = new DOMDocument("1.0", "utf-8"); @$dom->loadHTMLFile('http://sports.yahoo.com/news/messis-tax-hearing-put-back-122033643--sow.html'); $content = $dom->getElementById('yog-content'); var_dump($content);

Member Avatar
Member Avatar
+0 forum 4

I'm trying to create an xml document without converting html entities but when I create and save the file with DOMDocument the < and > characters are converted to &lt; and &gt; so trying to wrap copy within <![CDATA[]]> is proving problematic. Example of my code below: // Initiate the XML $doc = new DOMDocument('1.0', 'UTF-8'); $doc->formatOutput = true; $r = $doc->createElement("advertising"); $doc->appendChild($r); // <ad> $ad = $doc->createElement('ad'); // <TITLE> $title = $doc->createElement('TITLE'); $title->appendChild($doc->createTextNode('<![CDATA['.$v_title.']]>')); $ad->appendChild($title); // </ad> $r->appendChild($ad); // Save xml $doc->saveXML(); $doc->save('ads.xml'); Could anyone tell me how I prevent this?

Member Avatar
Member Avatar
+0 forum 2

I have a problem while creating an xml file in php.I am not getting th root element.But all other elements are been outputted in the result.What might be the reason????Any help would be appreciated.The code is depicted below.order is my root element. <?php $url='success.xml'; //$xml = simplexml_load_file($url); $name = htmlentities($_POST['name']); $age = htmlentities($_POST['age']); $doc = new DOMDocument(); $root=$doc->createElement("order"); $doc->appendChild($root); $textareaNode = $doc->createElement("name"); $textNode = $doc->createTextNode($name); $textareaNode->appendChild($textNode); $doc->appendChild($textareaNode); $textareaNode = $doc->createElement("age"); $textNode = $doc->createTextNode($age); $textareaNode->appendChild($textNode); $doc->appendChild($textareaNode); //header('Content-Type: text/xml'); echo $doc->save($url); ?> the above is my getdata.php page <html> <body> <form name="form" action="getdata.php" method="post"> <table> <tr> <td>name</td> <td><input type="text" name="name" /></td> </tr> …

Member Avatar
Member Avatar
+0 forum 5

Hi all, I am dealing a small issue. I am missing something silly :). My need is that I want the entire lines between <TABLE> </TABLE> with no modifications. [CODE]<?php $some_string = <<<STR <HR noShade size=2> <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR="" > <TR BGCOLOR="c1ffcc"> <TH ALIGN="LEFT" COLSPAN=22> <font face="Arial,Helvetica,Geneva,Swiss,Verdana" size="2" color="black">Baseline Comparison for Request Id: </font></TH> </TR> <TR BGCOLOR="lightblue"> <TH COLSPAN=1> </TH> </TABLE> </body> </html> STR; $match = preg_match('`<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR="" > (.*)</TABLE>`i', $some_string,$table); echo $match; print_r($table); [/CODE] But this code doesn't fetch me the desired output. Any help will be highly appreciated.

Member Avatar
Member Avatar
+0 forum 1

Hi All, I installed php 5 in my linux pc. My phpinfo() says libXML support active libXML Version 2.6.23 libXML streams enabled But still I cannot use DOMDocument in my script. When I use it in my script, Class 'DOMDocument' not found in /var/www/html/getcontent_3.php Any pointers will be very much appreciated. And also I need this badly to traverse my html contents. I cannot re-install libxml package with "yum" as I am not connected with internet.Please let me know any offline installation is possible. Any other equilent is available in php and its performance comparing to DOMDocument.

Member Avatar
Member Avatar
+0 forum 1

Hello. My problem is this: I have a table, for which the row and cols number is given by the user. They contai images. Occasionally a cells picture will be changed. The question I have is this: How to do that? I will be able to compute which cell need to be changed, so indexing will not be a problem. [CODE] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Untitled Document</title> <script language="JavaScript" type="text/javascript"> function createfield() { var hosz_val = document.Jatektermeretek.hosz.value; var szel_val = document.Jatektermeretek.szél.value; var body= document.getElementsByTagName("body"); var hely= document.getElementById("game_div"); var jatekter= document.createElement("table"); var jatekter_body = …

Member Avatar
Member Avatar
+0 forum 2

I am starting out with PHP and in my project I'm trying to fetch XML data from a url and parsing it for data. Now the url that I use is being fetched from a webpage and hence I know that it is correct and it exists. Still, when I try to execute the page I get the following errors: [ICODE] Warning: DOMDocument::load() [domdocument.load]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\Users\Siddharth Dahiya\Dropbox\www\Site\includes\tw_worlds.php on line 138 [/ICODE] The code in question is: [CODE=PHP] //Problem function function PopulateSettings() { set_time_limit(60000); //Lots of data hence large load time... $rtnVal = …

Member Avatar
Member Avatar
+0 forum 1

Im new to php and have been struggling with this for some time, but I expect its something simple. Basically I have some code below which I want to use to display an events board. -Info for each event comes from a separate xml file for each event. -XML files are named by date, ie today would be 050611.xml (DD/MM/YY) -Load all XML files in a directory and display items by tag name automatically. [B]As it is my code works fine. It finds all files in the directory that = more than today date and adds them to an array. …

Member Avatar
Member Avatar
+0 forum 1

hey people, i have the following problem, i'm setting up a webshop with over 2k items and every 6months the prices are changing(wines) so i was wondering how to import an xml file into a mysql database without having to go in phpmyadmin. this because i don't want the people for who i'm making the website have access there to destroy the whole database. this is what i got so far: [CODE]<?php include "header.php"; ?> <br><br><br> <h1>Database updaten</h1> <form enctype="multipart/form-data" action="import.php" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="20000000" /> <table width="600"> <tr> <td>Names file:</td> <td><input type="file" name="file" /></td> <td><input type="submit" value="Upload" /></td> …

Member Avatar
Member Avatar
+0 forum 32

I have this code: I'm trying to have my program download all the images (that contains "jpg") from a site. [CODE]Dim doc As IHTMLDocument2 = DirectCast(WebBrowser1.Document.DomDocument, IHTMLDocument2) Dim imgRange As IHTMLControlRange = DirectCast(DirectCast(doc.body, HTMLBody).createControlRange(), IHTMLControlRange) For Each img As IHTMLImgElement In doc.images If img.nameProp.Contains("jpg") Then imgRange.add(DirectCast(img, IHTMLControlElement)) imgRange.execCommand("Copy", False, Nothing) Using bmp As Bitmap = DirectCast(Clipboard.GetDataObject().GetData(DataFormats.Bitmap), Bitmap) 'bmp.Save("test.gif", System.Drawing.Imaging.ImageFormat.Gif) bmp.Save("MyImages") End Using End If Next WebBrowser1.Navigate("http://www.yahoo.com")[/CODE] Getting an error on line 1 with System.NullReferenceException (Object reference not set to an instance of an object).

Member Avatar
Member Avatar
+0 forum 6

The End.