Ler arquivo XML que se encontra no desktop
Bom dia, sou novo na programação em JavaScript.
Estou tentando ver um arquivo, XML, que esta em uma pasta em meu desktop. Ate que consigo algumas coisas, como achar o arquivo e carregar o nome dele em um campo TEXT no html.
Mas o que realmente preciso e carregar o conteúdo de suas tags em campos específicos.
Fiz o seguinte cógido com base em pesquisas da internet
/ Seleciona o arquivo XML e/
function CarregaDados() {
var file = document.getElementById('fileToUpload').files[0];
if(file)
document.getElementById('txtXMLArq').value = file.name;
var ajx = new XMLHttpRequest();
ajx.onreadystatechange = function (){
if (ajx.readyState == 4){
var x = ajx.responseXML;
alert(x);
x.getElementByTagName("chCTe")[0].fisrsChild.nodeValue;
document.getElementById('ChaveAcesso').value = x;
}
}
ajx.open("POST", document.getElementById('fileToUpload').files);
ajx.send(null);
}O formlário... quero carregar o conteudo do XML (um conhecimento de transporte) para os campos: ChaveAcesso, serie, txtCte.
<form name="form-imp_cte" method="post" action="" id="form-imp_cte">
<div id="accordion">
<fieldset>
<legend> Conhecimento Eletrônico </legend>
<div>
<label for="txtXMLArq" >Arquivo XML</label>
<input name="txtXMLArq" type="text" id="txtXMLArq" size="60" required>
<input type="hidden" name="carregar" id="carregar" value="carregar" />
<input type="file" alt="Submit" name="fileToUpload" id="fileToUpload" onchange="CarregaDados();"/>
</div>
<br/>
<div id="ChaveAcesso">
<label for="ChaveAcesso">Chave de acesso</label>
<input name="ChaveAcesso" type="text" id="ChaveAcesso" size="50" maxlength="44">
<img src="../imagem/copy.png" width="20" height="20" align="texttop" id="copiar" />
</div>
<div>
<label>Série</label>
<input name="txtSerie" id="txtSerie" type="text" size="5" maxlength="5">
<span>Número do CT-e</span>
<input name="txtCte" id="txtCte" type="text" size="14" maxlength="10"/>
</div>
</fieldset>
</form>Discussão (1)
Carregando comentários...