I am just start with PHP and XML, my xml file (phuket.xml) as
<Rx>
<hotel hno="676386">
<hno>676386</hno>
<region>phuket</region>
<hoteltag>3rdstreet</hoteltag>
<prov_id>73</prov_id>
<prov_en>Phuket</prov_en>
<prov_th>ภูเก็ต</prov_th>
<hotelname>3 Rd Street Cafe & Guesthouse</hotelname>
<hotelname_th>สายสามคาเฟ่ แอนด์เกสต์เฮ้าส์</hotelname_th>
<hoteladr>Kata Night Bazaar 100/3-4, Kata Road, Karon</hoteladr>
<hotelcity>Muang, Phuket 83100</hotelcity>
<location>Kata Beach</location>
<hotellink note="depreciated">
http://www.R24.org/thailandallhotel.com/phuket/3rdstreet/
</hotellink>
<hotellink2>
http://thailandallhotel.com.r24.asia/676386/3-Rd-Street-Cafe-and-Guesthouse
</hotellink2>
<minrate_th excl="17%">1020</minrate_th>
<minrate_us excl="17%">34.22</minrate_us>
<minrate cur="USD" sym="$" sgn="$" dec="2">34.22</minrate>
<breakfast>excl</breakfast>
<promote/>
<geo_lat>7.8256</geo_lat>
<geo_long>98.2969</geo_long>
<distance_mt/>
<list_ctrl>3</list_ctrl>
<rating>2.5</rating>
</hotel>
<hotel hno="676282">
<hno>676282</hno>
<region>phuket</region>
<hoteltag>woraburiphuket</hoteltag>
<prov_id>73</prov_id>
<prov_en>Phuket</prov_en>
<prov_th>ภูเก็ต</prov_th>
<hotelname>Woraburi Phuket Resort & Spa</hotelname>
<hotelname_th>วรบุรี ภูเก็ต รีสอร์ท แอนด์ สปา</hotelname_th>
<hoteladr>199, 201 Tambol Karon, Amphur Karon,</hoteladr>
<hotelcity>Phuket 83100</hotelcity>
<location>Karon Beach</location>
<hotellink note="depreciated">
http://www.R24.org/thailandallhotel.com/phuket/woraburiphuket/
</hotellink>
<hotellink2>
http://thailandallhotel.com.r24.asia/676282/Woraburi-Phuket-Resort-and-Spa
</hotellink2>
<minrate_th excl="17%">1540</minrate_th>
<minrate_us excl="17%">51.71</minrate_us>
<minrate cur="USD" sym="$" sgn="$" dec="2">51.71</minrate>
<breakfast>incl</breakfast>
<promote>recommend</promote>
<geo_lat>7.8440</geo_lat>
<geo_long>98.2952</geo_long>
<distance_mt/>
<list_ctrl>3</list_ctrl>
<rating>3.0</rating>
</hotel>
.
.
.
</Rx>
I try to load above xml file to mysql according to
<?php
$oDOM = new DOMDocument();
$oDOM->loadXML(file_get_contents('phuket.xml')); #See: http://msdn.microsoft.com/en-us/library/ms762271(VS.85).aspx
foreach ($oDOM->getElementsByTagName('hotel') as $oBookNode)
{
$sSQL = sprintf(
"INSERT INTO phuket (hno, region, hoteltag) VALUES ('%s', '%s', '%s')",
mysql_real_escape_string($oBookNode->getElementsByTagName('hno')->item(0)->nodeValue),
mysql_real_escape_string($oBookNode->getElementsByTagName('region')->item(0)->nodeValue),
mysql_real_escape_string($oBookNode->getElementsByTagName('hoteltag')->item(0)->nodeValue)
);
$rResult = mysql_query($sSQL);
if(mysql_errno() > 0)
{
printf(
'<h4 style="color: red;">Query Error:</h4>
<p>(%s) - %s</p>
<p>Query: %s</p>
<hr />',
mysql_errno(),
mysql_error(),
$sSQL
);
}
}
?>
The result come out with the following error
Warning: DOMDocument::loadXML() [domdocument.loadxml]: Extra content at the end of the document in Entity, line: 27 in C:\Ampps\www\php\LoadXMLNode.php on line 3
how can i correct the code.
Thanks in advance for suggestion.