473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

DOMParser, XML and nested nodes - help needed.

Hi, I'm trying to build a filemanager for a cms. I'd like to have a page with JS that asks the server for the filelist, which in turn answers with a XML document.

This is a sample of the XML answer:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-15"?>
  2. <items tot="1">
  3. <item iid="60dddfb31b978dc4c36d4475211e6672" key="fid" title=" C-nar.jpg">
  4. <node nType="icon" editable="false" key="thumb" width="720" height="576">[[url]]</node>
  5. <node nType="parent" editable="false">
  6.     <subnode nType="value" editable="true" key="title" title="Titolo"> C-nar.jpg</subnode>
  7.     <subnode nType="value" editable="true" key="caption" title="Descrizione">Amaro al Sapor di carciofo</subnode>
  8.     <subnode nType="value" editable="false" key="link" title="Link">[[url]]</subnode>
  9. </node>
  10.  
  11. <node nType="select" editable="true" key="uid" title="Proprietario">
  12.     <option value="1" selected="true">Amministratore</option>
  13.     <option value="10000001" selected="false">SuperAdmin</option>
  14.     <option value="2" selected="false">Pongi</option>
  15. </node>
  16. <node nType="select-multi" editable="true" key="groups:::gid" title="Visibile ai gruppi">
  17. <option value="1" selected="true">Amministratori</option>
  18. <option value="2" selected="false">Reggio Emilia</option>
  19. <option value="3" selected="true">Pippo</option>
  20. <option value="4" selected="false">Newsletter</option>
  21. </node>
  22. <node nType="value" editable="false" key="fsize">61.826KB</node>
  23. <node nType="remove" editable="false"></node>
  24. </item>
  25. </items>
I did so with a number of others scripts, but this one is the only that seems to give me problems.
Firefox doesn't alert me of XML syntax errors, but when I'm going to traverse it through Javascript I can get the first childNodes (the <item> nodes) but everything below this level is parsed as a single #text node. How could it be?
I hope you can spot a big mistake in my xml.
Thanks everyone.
Jun 21 '07 #1
4 2607
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

Can you post the code you are using?
Jun 21 '07 #2
Ok, that's not the actual code but I just skimmed some unimportant things
Expand|Select|Wrap|Line Numbers
  1. var tb = document.getElementById("myTable").tBody;
  2. var XmlObj = parsexml(http.responseText);
  3. for(var j=0;j<XmlObj.childNodes.length;j++) {
  4.     if(XmlObj.childNodes[j].nodeType != 1) continue;
  5.     var aItem = XmlObj.childNodes[j];
  6.     aRow = document.createElement("TR");
  7.     for(var i=0;i<XmlObj.childNodes[j].childNodes[i].length;i++) {
  8.         var aItemNode = XmlObj.childNodes[j].childNodes[i];
  9.         if(aItemNode.nodeType != 1) continue;
  10.         // aValue is a Cell within the Row.
  11.         var aValue = XmlObj.childNodes[j].childNodes[i];
  12.         // append an item (aValue) to another element (aRow).
  13.         // myAppendItem(aValue, aRow);
  14.     }
  15.     tb.appendChild(aRow);
  16. }
  17.  
The inner "for" iteration runs just once to find out that the only childNode is a #text one (nodeType != 1).
Jun 21 '07 #3
acoder
16,027 Expert Mod 8TB
That is probably your problem. There are 12 different node types - see link. If you want to check for a text node, check for node type 3.
Jun 22 '07 #4
Ok, that's true, but even if I skip the check for the nodeType, it turns out to be a node with no childNodes, as if the DOMParser won't traverse completely my xml, but without warnings or errors. That's why I'm lost.
Jun 26 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Jeff Lanfield | last post by:
First of all, I apologize if coalescing is not the right term to describe my problem. I have a tree where each node has the same set of attributes (is the same entity) but child nodes should...
0
by: Yang Xiao | last post by:
Hi all, I'm having some problems with parsing XML with DOMParser. What I want is to filter out particular elements in the XML, the sample XML looks like this. Thanks in advance. Yang ...
2
by: DKM | last post by:
I recently found out that the below code works in FireFox 1.0.4. str = "<b>Hello world!!!</b>"; var doc = new DOMParser().parseFromString(str, "text/xml");...
1
by: Hazz | last post by:
I have 5 tables in SQL Server. Each with the following design and a sample chain of the relationships from the root (WRL - World) UUS is the 'Code' of the first table and it is the 'Parent' value...
6
by: jwvai316 | last post by:
I don't really know how to say it so I just say it a nested linklist. How do you make LinkLists inside LinkList? Can anyone help me for this? I think an example program will help me a lot. ...
1
by: Carlitos | last post by:
Hi there, I'm a beginner on XML. At this moment I am working on a conversion to C# of a (pretty large) program originally coded in Java. It's not much what the JLCA does when converting XML...
3
by: sfeher | last post by:
Hi All, The following code returns a valid xmlDoc (since I can evaluate and selectNodes) but its value is "xmlDoc= null" ?! Or at least this is what the FireBug shows and (xmlDoc===null) is...
1
by: =?Utf-8?B?SmVyZW15X0I=?= | last post by:
I am working on an order entry program and have a question related to deserializing nodes with nested elements. The purchase order contains multiple line items which I select using an...
5
by: vunet | last post by:
I used DOMParser to convert a response string to XML object: DOMParser.parseFromString() In browsers where DOMParser is not supported (Safari 1-2 for my case) I cannot use DOMParser. What...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.