Asked by duncanb7
at 2024-06-07 00:56:56
Point:125 Replies:4 POST_ID:828317USER_ID:11059
Topic:
PHP Scripting Language;Hypertext Markup Language (HTML);Web Languages/Standards
Dear Expert,
From following exmplle of example.php which is easily to extract xml data from example.xlm file, it just
use getElementsByTagName('file') in order to get the image file name in example.xml (example.png).
But how I convert HTML web paga data into XML format, because I would like to extract HTML data
by PHP coding.
The problem-1 : Converting HTML to XMLformat
THe problem-2, I use other way, I directly extract HTML data using example.php program and replace example.xml by mywebpage.html, and using getElementsByTagName('SPAN') to extract SPAN tag data
which is "116.200" but finaly it shown out no any result and no any error. It seem the php code
could not find out where SPAN tag is.
Question-1 Could you help on this and give some code hit to extract the tag <Span class="neg_bold">.nodevalue ?
THanks & Br
Duncan
mywebpage.html code is as follows:
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<span class="neg bold">116.200</span>
</body>
</html>
From following exmplle of example.php which is easily to extract xml data from example.xlm file, it just
use getElementsByTagName('file') in order to get the image file name in example.xml (example.png).
But how I convert HTML web paga data into XML format, because I would like to extract HTML data
by PHP coding.
The problem-1 : Converting HTML to XMLformat
THe problem-2, I use other way, I directly extract HTML data using example.php program and replace example.xml by mywebpage.html, and using getElementsByTagName('SPAN') to extract SPAN tag data
which is "116.200" but finaly it shown out no any result and no any error. It seem the php code
could not find out where SPAN tag is.
Question-1 Could you help on this and give some code hit to extract the tag <Span class="neg_bold">.nodevalue ?
THanks & Br
Duncan
mywebpage.html code is as follows:
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<span class="neg bold">116.200</span>
</body>
</html>
example.php
?php
$dom = new DomDocument();
$dom->prevservWhiteSpace = false;
if (!@$dom->load("example.xml")) {
echo "example.xml doesn't exist!";
return;
}
$imageList = $dom->getElementsByTagName('file');
$imageCnt = $imageList->length;
for ($idx = 0; $idx < $imageCnt; $idx++) {
print $imageList->item($idx)->nodeValue . "";
}
?>
?php
$dom = new DomDocument();
$dom->prevservWhiteSpace = false;
if (!@$dom->load("example.xml")) {
echo "example.xml doesn't exist!";
return;
}
$imageList = $dom->getElementsByTagName('file');
$imageCnt = $imageList->length;
for ($idx = 0; $idx < $imageCnt; $idx++) {
print $imageList->item($idx)->nodeValue . "";
}
?>
example.xml
<?xml version="1.0" encoding="utf-8" ?>
<root>
<box>
<file>example.png</file>
</box>
<content>
<item>
<image><file>example2.png</file></image>
<caption>The above image is an example</caption>
</item>
</content>
</root>
<?xml version="1.0" encoding="utf-8" ?>
<root>
<box>
<file>example.png</file>
</box>
<content>
<item>
<image><file>example2.png</file></image>
<caption>The above image is an example</caption>
</item>
</content>
</root>