Text/html page to XML using proxy php
I have a problem in co开发者_StackOverflow社区nverting a html page to xml, that I can call a specific tag name and accsess to data in specific tag. I tried with XMLHttpRequest, but doesn't work. Then I tried with XMLHttpRequest responseText and then convert String to XML with DOM parser, but that neither work (errors with parsing).I will need to use php proxy which will convert text to XML and here I need help... Thanks for answers!
If I got it right you can retrive the HTML with file_get_contents();
and then traverse it with DOMDocument();
Example:
<?php
$doc = new DOMDocument();
$doc->loadHTML(file_get_contents($file));
$elements = $doc->getElementsByTagName('*');
?>
Browsers do a very good job to convert non-xml to DOM.
- Load desired document with XMLHttpRequest
- Insert responseText into a html div element with
elem.innerHTML = xhr.responseText
- Access children using DOM API.
精彩评论