언어 설정

Menu
Sites
Language
XML File Parsing problem in Tizen SDK 2.3.0 for Wearable
Hi, I am having problem in XML File Parsing. XML File is not being Recognized by the SDK. Also I have tried with html file, but didn't get any workaround. Can anyone give me examples on that. I have tried with the following codes : while the file my_file.xml is put into the root folde, that is just above the "js" Folder. if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); console.log("IE7+, Firefox"); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); console.log("IE7-"); } xmlhttp.open("GET","../my_file.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; var str = xmlDoc.getElementsByTagName("p")[0].childNodes[0].nodeValue; In the Console I am getting following error: TypeError: 'null' is not an object (evaluating 'xmlDoc.getElementsByTagName')
Edited by: Abdur Rahman Khan on 02 12월, 2014
답변 바로가기

Responses

5 댓글
AVSukhov

Hello,

Verify that xmlDox isn`t null.

For example add following code:

if(xmlhttp.readyState == 4) {

xmlDoc = xmlhttp.responseXML;

}

colin Rao

xmlhttp.open("GET","../my_file.xml",false); 

Seems it's like to simulate a http request to got a local file. It's ok, but it's not a good manner. I've try find a xml parse function from the help content, but failed. Seems the Tizen web app framework doesn't support the original xml file parse, such as:

xmldoc = xmlDocument.loadFrom("filepath", "rw");

xmlElement = xmldoc.findElement("...");

I don't find such like interface from the help content. Hope that's true in future!!!

Abdur Rahman Khan

Finally I have managed to get data from Local XML file with the following Code:

============ Code (Don't know why do I have to break into 2 line) ============

str = xmlDoc.getElementsByTagName("B");   // Child Tag.

for(index=0; index<str.length; index++)

{

str_array[index] = str[index].childNodes[0].nodeValue;

}

========= HTML Content (why <BODY> Tag have to be used in XML File ?) =============

<?xml version="1.0" encoding="UTF-8"?>

<BODY>

<P> <B>Hello</B> Hello Everyone!</P>

<P> <B>Welcome</B> Welcome to Tizen SDK !</P>

</BODY>

========== Data ==========

str_array[0] = Hello

str_array[1] = Welcome

 

I have managed to Parse throuh the <B> Tag without any problem. But I have a new Query, is it possible to parse through strings which are not in any Child Tag, such as Hello Everyone! and Welcome to Tizen SDK ! in the above example ? I think if there is any way to get <P> Tag Data as a string, then it will be possible. But didn't found any way as I am a Newbie in JavaScript. :(

Abdur Rahman Khan

Sorry the File is NOT HTML, it is in XML.

Mark as answer
colin Rao

try

str = xmlDoc.getElementsByTagName("P");   // Child Tag.

for(index=0; index<str.length; index++)

{

str_array[index] = str[index].childNodes[0].innerText;

}