Autor Zpráva
adra234
Profil
ukazka http://www.eurosecom.sk/chrome/

v IE funguje v Chrome nie.

Problem je v tom za ak poslem zo servera cez echo.... xml subor tak chrome ho neprecita zahlasi nespravnu strukturu xml suboru

???

index.php
<!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>




<script type="text/javascript" src="ovr_grid_xml.js"></script>



</head>
<body onload="overgrid();" >

<FORM name="form1" method="post" action="" >
<table width="100%" >
<tr>


<td width="100%" align="left" style=" background-color:#ffff90; color:black; font-weight:bold; height:12px; font-size:16px; " >
<INPUT type="text" name="rtxgr" id="rtxgr" class="a" size="20" maxlength="20">

</td>
</tr>
</table>
</FORM>


</body>
</html>

ovr_grid_xml.js
// holds an instance of XMLHttpRequest
var xmlHttp = createXmlHttpRequestObject();

// creates an XMLHttpRequest instance
function createXmlHttpRequestObject()
{
// will store the reference to the XMLHttpRequest object
var xmlHttp;
// this should work for all browsers except IE6 and older
try
{
// try to create XMLHttpRequest object
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
// assume IE6 or older
var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
"MSXML2.XMLHTTP.5.0",
"MSXML2.XMLHTTP.4.0",
"MSXML2.XMLHTTP.3.0",
"MSXML2.XMLHTTP",
"Microsoft.XMLHTTP");
// try every prog id until one works

for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)
{
try
{
// try to create XMLHttpRequest object
xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
}
catch (e) {}
}
}
// return the created object or display an error message
if (!xmlHttp)
alert("Error creating the XMLHttpRequest object.");
else
return xmlHttp;
}

// read a file from the server
function overgrid()
{
// only continue if xmlHttp isn't void
if (xmlHttp)
{
// try to connect to the server
try
{

var prm1 = 55;
var prm2 = 0;
var prm3 = 0;
var prm4 = 0;

// create the params string
var params = "prm1=" + prm1 + "&prm2=" + prm2 + "&prm3=" + prm3 +
"&prm4=" + prm4;

// initiate reading a file from the server
xmlHttp.open("GET", "daj_grid_xml.php?" + params, true);
//xmlHttp.open("GET", "grid.xml", true);
xmlHttp.onreadystatechange = cakajGrid;
xmlHttp.send(null);
}
// display the error in case of failure
catch (e)
{
alert("Can't connect to server:\n" + e.toString());
}
}
}


// function called when the state of the HTTP request changes
function cakajGrid()
{
// when readyState is 4, we are ready to read the server response
if (xmlHttp.readyState == 4)
{
// continue only if HTTP status is "OK"
if (xmlHttp.status == 200)
{
try
{

// vypis do tabulky samostatnej ;
tabulka_GridXML();

}
catch(e)
{
// display error message
alert("Error reading the response: " + e.toString());
}
}
else
{
// display status message
alert("There was a problem retrieving the data:\n" +
xmlHttp.statusText);

}
}
}


//odstranenie bielych znakov
function odstranBileZnaky( xml )
{
var citac;

for (citac = 0; citac < xml.childNodes.length; citac++) {

var aktUzel = xml.childNodes[citac];

if (aktUzel.nodeType == 1) {
odstranBileZnaky(aktUzel);
}

if (((/^\s+$/.test(aktUzel.nodeValue))) &&
(aktUzel.nodeType == 3)) {
xml.removeChild(xml.childNodes[citac--]);
}
}
}

// vypis do tabulky s parametrom
function tabulka_GridXML()
{
// read the message from the server
var xmlResponse = xmlHttp.responseXML;

//odstranBileZnaky(xmlResponse);

// catching potential errors with IE and Opera
if (!xmlResponse || !xmlResponse.documentElement)
throw("Invalid XML structure:\n" + xmlHttp.responseText);
// catching potential errors with Firefox
var rootNodeName = xmlResponse.documentElement.nodeName;
if (rootNodeName == "parsererror") throw("Invalid XML structure");
// obtain the XML's document element
xmlRoot = xmlResponse.documentElement;
// obtain arrays with book titles and ISBNs
pol01Array = xmlRoot.getElementsByTagName("pol01");
pol02Array = xmlRoot.getElementsByTagName("pol02");
pol03Array = xmlRoot.getElementsByTagName("pol03");

// generate HTML output
var grid = 0;
for (var i=0; i<pol01Array.length; i++)
{
grid = pol01Array.item(i).firstChild.data;
obrs = pol02Array.item(i).firstChild.data;
subob = pol03Array.item(i).firstChild.data;
}

document.forms.form1.rtxgr.value = grid;

}






daj_grid.php
<?php


//vytvorenie grid
// set the output content type as xml
header('Content-Type: text/xml Accept-Charset: utf-8; q=0.7');
//header('Content-Type: text/xml ');
// create the new XML document
$dom = new DOMDocument();

// create the root <response> element
$response = $dom->createElement('response');
$dom->appendChild($response);

// create the <vety> element and append it as a child of <response>
$vety = $dom->createElement('vety');
$response->appendChild($vety);

$prm1 = $_GET['prm1'];
//cisla 1az6 pismena a1 az f6

$jesu=0;


$txp01=5;
$txp02=2;
$txp03=3;

// create the title element for the veta
$pol01 = $dom->createElement('pol01');
$pol01Text = $dom->createTextNode($txp01);
$pol01->appendChild($pol01Text);

// create the pol02 element for the veta
$pol02 = $dom->createElement('pol02');
$pol02Text = $dom->createTextNode($txp02);
$pol02->appendChild($pol02Text);

// create the pol03 element for the veta
$pol03 = $dom->createElement('pol03');
$pol03Text = $dom->createTextNode($txp03);
$pol03->appendChild($pol03Text);

// create the <veta> element
$veta = $dom->createElement('veta');
$veta->appendChild($pol01);
$veta->appendChild($pol02);
$veta->appendChild($pol03);

// append <veta> as a child of <vety>
$vety->appendChild($veta);

//uloz xml strukturu
// build the XML structure in a string variable
$dom->encoding = 'utf-8';
$xmlString = $dom->saveXML();
// output the XML string
echo $xmlString;

// vystup textoveho retazca
//echo $xmlString;
//print $xmlString;

// konfigurace pro uložení
//$dom->formatOutput = TRUE;
//$dom->encoding = 'utf-8';
//$dom->save('grid.xml');
?>
Chamurappi
Profil
Reaguji na adru234:
chrome ho neprecita zahlasi nespravnu strukturu xml suboru
Ani se mu nedivím, když posíláš XML s hlavičkou Content-Type: text/xml Accept-Charset: utf-8; q=0.7. Já bych se na to na jeho místě také vybodl.
adra234
Profil
No to je pravda.

Dakujem Chamurappi
Petr ZZZ
Profil
adra234:
Správnou strukturu xml najdeš na stránce sitemaps.org.

Vaše odpověď

Mohlo by se hodit

Neumíte-li správně určit příčinu chyby, vkládejte odkazy na živé ukázky.
Užíváte-li nějakou cizí knihovnu, ukažte odpovídajícím, kde jste ji vzali.

Užitečné odkazy:

Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0