Search Results

Search found 177 results on 8 pages for 'domdocument'.

Page 1/8 | 1 2 3 4 5 6 7 8  | Next Page >

  • Enumerate registered namespaces of a PHP DOMDocument object

    - by zneak
    Hello world, For one of my projects, I'm using the DOMDocument class to load and manipulate XML documents. I'd need to retrieve every namespace used in the document; however, I can't find how I'd do that. The DOMDocument class has methods to get the namespace prefix of an URI or the URI of a namespace prefix, but I've seen nothing to actually enumerate registered namespaces. The SimpleXML library has a getNamespaces() method for that. Is there an equivalent for DOMDocument?

    Read the article

  • msxml domdocument stops working when I move to staging server

    - by blockhead
    I have some code that looks like this: Set xmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP") xmlHttp.Open "Get", myRSSfile, false xmlHttp.Send() myXML = xmlHttp.ResponseText Set xmlResponse = Server.CreateObject("MSXML2.DomDocument") xmlResponse.async = false xmlResponse.LoadXml(myXML) Set xmlHttp = Nothing Set objLst = xmlResponse.getElementsByTagName("item") Set xmlResponse = Nothing NoOfHeadlines = objLst.length - 1 Response.Write NoOfHeadlines This worked find on my development server. When I moved it over to a staging server (which I have no control over, and no nothing about), NoOfHeadlines returns 0. It seems obvious to me that DomDocument is not working the way its supposed to. Is this a version issue? How do I find out what version of DomDocument is on the staging server? Is there another possibility?

    Read the article

  • Php DOMDocument Htmlentities problem

    - by scopus
    Hi, I use DOMDocument. My code here. $dom = new DOMDocument('1.0', 'utf-8'); $textNode = $dom->createTextNode('<input type="text" name="lastName" />'); $dom->appendChild($textNode); echo $dom->saveHTML(); Output: &lt;input type="text" name="lastName" &gt; But i want to disable htmlentities. How can i do?

    Read the article

  • Extending DOMDocument and DOMNode: problem with return object

    - by Glauber Rocha
    I'm trying to extend the DOMDocument class so as to make XPath selections easier. I wrote this piece of code: class myDOMDocument extends DOMDocument { function selectNodes($xpath){ $oxpath = new DOMXPath($this); return $oxpath->query($xpath); } function selectSingleNode($xpath){ return $this->selectNodes($xpath)->item(0); } } These methods return a DOMNodeList and a DOMNode object, respectively. What I'd like to do now is to implement similar methods to the DOMNode objects. But obviously if I write a class (myDOMNode) that extends DOMNode, I won't be able to use these two extra methods on the nodes returned by myDOMDocument because they're DOMNode (and not myDOMNode) objects. I'm rather a beginner in object programming, I've tried various ideas but they all lead to a dead-end. Any hints? Thanks a lot in advance.

    Read the article

  • Loop over DOMDocument

    - by Zoredache
    I am following the suggestion from this question Robust, Mature HTML Parser for PHP, about parsing html that may be malformed with DOMDocument. Is there any easy way to loop over the parsed document? So I would like to loop over html like this. $html='<ul> <li>value1</li> <li>value1</li> <li>value3</li> </ul> <p>hello world</p>'; $doc = new DOMDocument(); $doc->loadHTML($html); ??? foreach (??? as $node) { print $node->nodeName.':'.$node->nodeValue; } And get results somewhat like this. ul: li:value1 li:value2 li:value3 p:hello world

    Read the article

  • Getting content of the node which has childs via DOMDocument

    - by altern
    I have following html: <html ><body >Body text <div >div content</div></body></html> How could I get content of body without nested <div>? I need to get 'Body text', but do not have a clue how to do this. result of running $domhtml = DOMDocument::loadHTML($html); print $domhtml->getElementsByTagName('body')->item(0)->nodeValue; is 'Body textdiv content', which is not exactly what I want to get

    Read the article

  • Parse HTML with PHP's HTML DOMDocument

    - by Mint
    I was trying to do it with "getElementsByTagName", but it wasn't working, I'm new to using DOMDocument to parse HTML, as I used to use regex until yesterday some kind fokes here told me that DOMEDocument would be better for the job, so I'm giving it a try :) I google around for a while looking for some explains but didn't find anything that helped (not with the class anyway) So I want to capture "Capture this text 1" and "Capture this text 2" and so on. Doesn't look to hard, but I can't figure it out :( <div class="main"> <div class="text"> Capture this text 1 </div> </div> <div class="main"> <div class="text"> Capture this text 2 </div> </div>

    Read the article

  • [PHP] DOMDocument load on a page returning 400 Bad Request status

    - by PeteWilliams
    Hiya, I'm trying to use the Last.fm API for an application I'm creating, but am having some problems with validation. If an API request gives an error it returns a code and message in the response XML like this: <lfm status="failed"> <error code="6">No user with that name</error> </lfm> However, the request also returns an HTTP status of 400 (or in some cases 403) which DOMDocument considers an error and so then refuses to parse the XML. Is there any way round this, so that I can retrieve the error code and message? Thanks Pete

    Read the article

  • php domDocument variables

    - by geoffs3310
    Hi, I have the following code at the moment: $ip = '195.72.186.157'; $xmlDoc = new DOMDocument(); $xmlDoc->loadXML(file_get_contents('http://www.geoffmeierhans.com/services/geo-locator/locate/?ip='.$ip.'&output=xml')); foreach($xmlDoc->getElementsByTagName('city') as $link) { $links = array('text' => $link->nodeValue); } $city = $links['text']; echo $city; Is there a better way to get the city variable? Since there is only one tag called city a loop isn't really needed but I can't get it to work any other way

    Read the article

  • How to get Anchor text using DomDocument?

    - by Click Upvote
    Say I have this html: <a href="http://example.com">Test</a> I parse it using dom document with this code: $dom = new DomDocument(); @$dom->loadHTML($html); $urls = $dom->getElementsByTagName('a'); And then I run this code: foreach ($urls as $url) { //echo "<br> {$url->getAttribute('href')} , {$url->getAttribute('title')}"; foreach ($url->attributes as $a) { echo "<br>$a->name is $a->value"; } echo "<hr><br>"; } When I do this, I only see 'href' as an attribute of the url, there's no way to get the 'anchor text' (in the above case 'Test'). How can I get the anchor text of the link?

    Read the article

  • PHP DomDocument class unable access domnode

    - by turbod
    Hi. I dont parse this url: http://foldmunka.net $ch = curl_init("http://foldmunka.net"); //curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //not necessary unless the file redirects (like the PHP example we're using here) $data = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); clearstatcache(); if ($data === false) { echo 'cURL failed'; exit; } $dom = new DOMDocument(); $data = mb_convert_encoding($data, 'HTML-ENTITIES', "utf-8"); $data = preg_replace('/<\!\-\-\[if(.*)\]>/', '', $data); $data = str_replace('<![endif]-->', '', $data); $data = str_replace('<!--', '', $data); $data = str_replace('-->', '', $data); $data = preg_replace('@<script[^>]*?>.*?</script>@si', '', $data); $data = preg_replace('@<style[^>]*?>.*?</style>@si', '', $data); $data = mb_convert_encoding($data, 'HTML-ENTITIES', "utf-8"); @$dom->loadHTML($data); $els = $dom->getElementsByTagName('*'); foreach($els as $el){ print $el->nodeName." | ".$el->getAttribute('content')."<hr />"; if($el->getAttribute('title'))$el->nodeValue = $el->getAttribute('title')." ".$el->nodeValue; if($el->getAttribute('alt'))$el->nodeValue = $el->getAttribute('alt')." ".$el->nodeValue; print $el->nodeName." | ".$el->nodeValue."<hr />"; } I need the alt, title attributes and the simple text, but this page i cannot access the nodes within the body tag.

    Read the article

  • PHP DOMDocument getElementsByTagname??

    - by FFish
    This is driving me bonkers... I just want to add another img node. $xml = <<<XML <?xml version="1.0" encoding="UTF-8"?> <gallery> <album tnPath="tn/" lgPath="imm/" fsPath="iml/" > <img src="004.jpg" caption="4th caption" /> <img src="005.jpg" caption="5th caption" /> <img src="006.jpg" caption="6th caption" /> </album> </gallery> XML; $xmlDoc = new DOMDocument(); $xmlDoc->loadXML($xml); $album = $xmlDoc->getElementsByTagname('album')[0]; // Parse error: syntax error, unexpected '[' in /Applications/XAMPP/xamppfiles/htdocs/admin/tests/DOMDoc.php on line 17 $album = $xmlDoc->getElementsByTagname('album'); // Fatal error: Call to undefined method DOMNodeList::appendChild() in /Applications/XAMPP/xamppfiles/htdocs/admin/tests/DOMDoc.php on line 19 $newImg = $xmlDoc->createElement("img"); $album->appendChild($newImg); print $xmlDoc->saveXML(); Error:

    Read the article

  • PHP DOMDocument Error Handling Problem

    - by Jon
    I'm having trouble trying to write an if statement for DOM that will check if $html is blank. However whenever the html page does end up blank, it just removes everything that would be below DOM (including what I had to check if it was blank). $html = file_get_contents("http://example.com/"); $dom = new DOMDocument; @$dom->loadHTML($html); $links = $dom->getElementById('dividhere')->getElementsByTagName('img'); foreach ($links as $link) { echo $link->getAttribute('src'); } All this does is grab an image url in the specified div, which works perfectly until the page is a blank html page. I've tried using SimpleHTMLDOM, which didn't work either (it didn't even fetch the image on working pages). Did I happen to miss something with this one or am I just missing something in both? include_once('simple_html_dom.php') $html = file_get_html("http://example.com/"); foreach($html->find('div[id="dividhere"]') as $div) { if(empty($div->src)) { continue; } echo $div->src; }

    Read the article

  • Is it possible to split HTML using DOMDocument?

    - by Lynn Adrianna
    Using DOMDocument, is it possible to split a block of HTML by text wrapped in tags and those that are not, while maintaining the order? Sorry, if this doesn't make sense. My example should make it clear. Let's say I have the following block of HTML: text1<b style="color:pink">text2</b>text3<b>text4</b> <b style="font-weight:bold">text5</b> Is it possible create an array as such: array( [0] => text1 [1] => <b style="color:pink">text2</b> [2] => text3 [3] => <b>text4</b> [4] => [5] => <b style="font-weight:bold">text5</b> ) Below is my current working solution, which uses a regular expression, to split the HTML. $tokens = preg_split('/(<b\b[^>]*>.*?<\/b>)/i', $html, null, PREG_SPLIT_DELIM_CAPTURE); However, I always read that it is a bad idea to parse HTML using regular expressions, so was just wondering if there is a better way.

    Read the article

  • html to text with domdocument class

    - by turbod
    How to get a html page source code without htl tags? For example: <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta http-equiv="content-language" content="hu"/> <title>this is the page title</title> <meta name="description" content="this is the description" /> <meta name="keywords" content="k1, k2, k3, k4" /> start the body content <!-- <div>this is comment</div> --> <a href="open.php" title="this is title attribute">open</a> End now one noframes tag. <noframes><span>text</span></noframes> <select name="select" id="select"><option>ttttt</option></select> <div class="robots-nocontent"><span>something</span></div> <img src="url.png" alt="this is alt attribute" /> I need this result: this is the page title this is the description k1, k2, k3, k4 start the body content this is title attribute open End now one noframes tag. text ttttt something this is alt attribute I need too the title and the alt attributes. Idea?

    Read the article

  • CData section not finished problem

    - by tomaszs
    When I use DOMDocument::loadXML() for my XML below I get error: Warning: DOMDocument::loadXML() [domdocument.loadxml]: CData section not finished http://www.pdclipart.org/displayimage.php?album=se in Entity, Warning: DOMDocument::loadXML() [domdocument.loadxml]: Premature end of data in tag image line 7 in Entity Warning: DOMDocument::loadXML() [domdocument.loadxml]: Premature end of data in tag quizz line 3 in Entity Warning: DOMDocument::loadXML() [domdocument.loadxml]: Premature end of data in tag quizzes line 2 in Entity Fatal error: Call to a member function getElementsByTagName() on a non-object It seems to me that my CData sections are closed but still I get this error. XML looks like this: <?xml version="1.0" encoding="utf-8"?> <quizzes> <quizz> <title><![CDATA[Title]]></title> <descr><![CDATA[Some text here!]]></descr> <tags><![CDATA[one tag, second tag]]></tags> <image><![CDATA[http://www.site.org/displayimage.php?album=search&cat=0&pos=1]]></image> <results> <result> <title><![CDATA[Something]]></title> <descr><![CDATA[Some text here]]></descr> <image><![CDATA[http://www.site.org/displayimage.php?album=search&cat=0&pos=17]]></image> <id>1</id> </result> </results> </quizz> </quizzes> Could you help me discover what is the problem?

    Read the article

  • WebKit & Objective-C: how to parse a HTML string into a DOMDocument?

    - by Rinzwind
    How do you get a DOMDocument from a given HTML string using WebKit? In other words, what's the implementation for DOMDocumentFromHTML: for something like the following: NSString * htmlString = @"<html><body><p>Test</body></html>"; DOMDocument * document = [self DOMDocumentFromHTML: htmlString]; DOMNode * bodyNode = [[document getElementsByTagName: @"body"] item: 0]; // ... etc. This seems like it should be straightforward to do, yet I'm still having trouble figuring out how :( ...

    Read the article

  • Salesforce/PHP - outbound messages (SOAP) - memory limit issue? DOMDocument::loadXML() issue?

    - by Phill Pafford
    I'm using Salesforce to send outbound messages (via SOAP) to another server. The server can process about 8 messages at a time, but will not send back the ACK file if the SOAP request contains more than 8 messages. SF can send up to 100 outbound messages in 1 SOAP request and I think this is causing a memory issue with PHP. If I process the outbound messages 1 by 1 they all go through fine, I can even do 8 at a time with no issues. But larger sets are not working. ERROR in SF: org.xml.sax.SAXParseException: Premature end of file Looking in the HTTP error logs I see that the incoming SOAP message looks to be getting cut of which throws a PHP warning stating: DOMDocument::loadXML() ... Premature end of data in tag ... PHP Fatal error: Call to a member function getAttribute() on a non-object This leads me to believe that PHP is having a memory issue and can not parse the incoming message due to it's size. I was thinking I could just set: ini_set('memory_limit', '64M'); // This has done nothing to fix the problem But would this be the correct approach? Is there a way I could set this to increase with the incoming SOAP request dynamically? UPDATE: Adding some code $data = fopen('php://input','rb'); $headers = getallheaders(); $content_length = $headers['Content-Length']; $buffer_length = 1000; $fread_length = $content_length + $buffer_length; $content = fread($data,$fread_length); /** * Parse values from soap string into DOM XML */ $dom = new DOMDocument(); $dom->loadXML($content); ....

    Read the article

  • Can I get the matched DOM string with PHP and DOMDocument?

    - by alex
    I've got my HTML inside of $html. dom = new DOMDocument(); $dom->loadHTML($html); $xpath = new DOMXPath($dom); $tags = $xpath->query('//div[@id="header"]'); foreach($tags as $tag) { var_dump($tag->nodeValue); // the innerHTML of that element var_dump($tag); // object(DOMElement)#3 (0) { } } Is there a way to get that node, or remove it? Basically, I'm parsing an existing website and need to remove elements from it. What method do I call to do that? Thanks

    Read the article

  • PHP encoding with DOMDocument

    - by Olivier Lalonde
    <tag> ????? ? </tag> When I try to get the content of the following code using DOMDocument functions, it returns something like: ÐÐ»ÐµÐºÑ Ðœ I've tried setting DOMDocument encoding to different values (UTF-8, ISO-8859-1), using mb_convert_encoding, iconv and utf8_encode but without success. How can I get "????? ?" instead of "ÐÐ»ÐµÐºÑ Ðœ" ? EDIT: The input is coming from a page loaded with curl. When I output the page content to my browser, the characters are displayed correctly (so I doubt the input is the problem).

    Read the article

  • Problems with creating XML with DOMDocument in PHP

    - by maralbjo
    The below code is fetched from php.net (http://docs.php.net/manual/en/domdocument.savexml.php). My problem is - it doesn't work. My only output from this is: "Saving all the document: Saving only the title part:". What am I missing here? $doc = new DOMDocument('1.0'); // we want a nice output $doc-formatOutput = true; $root = $doc-createElement('book'); $root = $doc-appendChild($root); $title = $doc-createElement('title'); $title = $root-appendChild($title); $text = $doc-createTextNode('This is the title'); $text = $title-appendChild($text); echo "Saving all the document:\n"; echo $doc-saveXML() . "\n"; echo "Saving only the title part:\n"; echo $doc-saveXML($title);

    Read the article

  • Twitter RSS feed, [domdocument.load]: failed to open stream:

    - by dave1019
    hi i'm using the following: <?php $doc = new DOMDocument(); $doc->load('http://twitter.com/statuses/user_timeline/XXXXXX.rss'); $arrFeeds = array(); foreach ($doc->getElementsByTagName('item') as $node) { $itemRSS = array ( 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue ); array_push($arrFeeds, $itemRSS); } for($i=0;$i<=3;$i++) { $tweet=substr($arrFeeds[$i]['title'],17); $tweetDate=strtotime($arrFeeds[$i]['date']); $newDate=date('G:ia l F Y ',$tweetDate); if($i==0) { $b='style="border:none;"'; } $tweetsBox.='<div class="tweetbox" ' . $b . '> <div class="tweet"><p>' . $tweet . '</p> <div class="tweetdate"><a href="http://twitter.com/XXXXXX">@' . $newDate .'</a></div> </div> </div>'; } return $tweetsBox; ?> to return the 4 most recent tweets from a given timeline (XXXXX is the relevant feed) It seems to work fine but i've recently been getting the following error sporadically: PHP error debug Error: DOMDocument::load(http://twitter.com/statuses/user_timeline/XXXXXX.rss) [domdocument.load]: failed to open stream: HTTP request failed! HTTP/1.1 502 Bad Gateway I've read that the above code is dependant on Twitter beign available and I know it gets rather busy sometimes. Is there either a better way of receiving twits, or is there any kind of error trapping i could do to just to display "tweets are currently unavailable..." ind of message rather than causing an error. I'm usnig ModX CMS so any parse error kills the site rather than just ouputs a warning. thanks.

    Read the article

  • DOMNode reference doesn't work anymore after appending it to another element twice

    - by Robbie Groenewoudt
    Hi, I'm using the a wrapper around the PHP5-class DOMDocument to generate my HTML. This makes it easy to modify the HTML by using the DOM. An example is creating element #1 and adding it to the element #2 and still be able to modify element #1 directly. A problem arises however with the following: Element #1 is added to element #2 Element #2 is added to element #3 Element #1 is modified but no changes are visible in the DOM of element #3 (which contains #1 and #2) A simplified sample code: <?php $doc1 = new DOMDocument(); $el1 = $doc1->createElement('h1', 'Hello'); $doc1->appendChild($el1); $doc2 = new DOMDocument(); $el2 = $doc2->createElement('h2', 'World'); $doc2->appendChild($el2); $doc3 = new DOMDocument(); $el3 = $doc3->createElement('h3', 'Today'); $doc3->appendChild($el3); // Import el1 into el2 $el1 = $doc2->importNode($el1, true); $el2->appendChild( $el1 ); $doc1 = $doc2; // Import el2 into el3 $el2 = $doc3->importNode($el2, true); //$el1 = $doc3->importNode($el1, true); Necessary? $el3->appendChild($el2); $doc2 = $doc3; // Modify el1 $el1->nodeValue = "Boo"; // This doesn't work? //$el2->nodeValue = "Boo"; // Changing element2 or 3 works... // Display result echo $doc3->saveHTML(); ?>` Any idea's on why modifying $el1 won't work? (While $el2 works fine) Or an easy way to set $el1 to the right element?

    Read the article

  • PHP parsing invalid html

    - by kmunky
    hi , i'm trying to parse some html that is not on my server $dom = new DOMDocument(); $dom->loadHTMLfile("http://www.some-site.org/page.aspx"); echo $dom->getElementById('his_id')->item(0); but php returns an error something like ID his_id already defined in http://www.some-site.org/page.aspx, line: 33. I think that is because DOMDocument is dealing with invalid html. So, how can i parse it even though is invalid?

    Read the article

1 2 3 4 5 6 7 8  | Next Page >