javascript xml text parser
hello
je dois d�velopper un parser de xml en js, pour parser des fichiers xml g�n�r�s par MCM (media center master) qui d�crivent des films (fichiers utilis�s par WMP, XBMC, etc)
le language est javascript, avec la version 1.7.0 de mozilla libjs, port� par mediatomb.
je n'ai donc bien �videmment pas acc�s � window.* ni � XMLParser ni � XMLHttp.* ni � la d�finition de class(), ni de prototype, etc
je dois faire �a en pur JS, sur une variable qui contient le contenu du fichier sans les retours chariot.
avec un simple split j'arrive d�j� � un r�sultat encourageant :
Code:
1 2 3 4 5 6 7
|
xml_content=<?xml version="1.0" encoding="utf-8"?><movie xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><title>movie title</title><originaltitle>original movie title</originaltitle><sorttitle>movie title (1995)</sorttitle><set></set><rating>7,3</rating><...><...>
tags=xml_content.split('><');
for (i in tags) {
print("playlist.js : tag="+tags[i]);
} |
result :
Code:
1 2 3 4 5 6 7 8 9
| tag=<?xml version="1.0" encoding="utf-8"?
tag=movie xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
tag=title>movie title</title
tag=originaltitle>original movie title</originaltitle
tag=sorttitle>movie title (1995)</sorttitle
tag=set
tag=/set
tag=rating>7,3</rating
... |
mais voil� je suis un informaticien et comme vous tous tr�s fain�ant, avant de continuer j'ai bien cherch� sur le net des parser xml en pur JS, j'en ai trouv� que 2 mais impossible de les adapter !
http://www.thomasfrank.se/downloadableJS/xml2json.js
http://wiki.unity3d.com/index.php?title=TinyXmlReader
ils utilisent des classe et des prototypes, que j'ai transform� en fonctions ind�pendantes mais sans succ�s aucun, j'ai des erreurs diverses et vari�es.
est-ce que quelqu'un a lui/elle m�me d�velopp� d�j� un xlml parser en pur JS ? :ccool: