473,804 Members | 3,672 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DOMParser, XML and nested nodes - help needed.

3 New Member
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 2629
acoder
16,027 Recognized Expert Moderator MVP
Welcome to TSDN!

Can you post the code you are using?
Jun 21 '07 #2
willywongi
3 New Member
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 Recognized Expert Moderator MVP
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
willywongi
3 New Member
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
3984
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 inherit attribute values from parent node. for example, say I have the following table: (nodeId int , color varchar, phone varchar) with two rows 5, "GREEN", "555-1212"
0
3076
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 <CATALOG>
2
3788
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"); document.getElementById("div1").appendChild(doc.documentElement); I knew how to manipulate document object. Now, I see that there is this DOMParser object that one can use in the browser in Javascript. What other objects are accessible in FireFox?
1
3077
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 of the second table, etc. Parent varchar 3 Name varchar 60 Code varchar 3 WRL United States UUS <- UUS California UCA <- UCA North Coast UNC <- UNC
6
2182
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. thank you.
1
2461
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 classes from Java to C# for several reasons, and basically leaves the programmer with the decision on how they will be converted (Reference: http://msdn.microsoft.com/asp.net/using/migrating/jspmig/phase1/xml/) At this point I am about to convert...
3
9972
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 true. var parser = new DOMParser(); var xmlDoc = parser.parseFromString( responseText, "text/xml"); // at this point: xmlDoc= null
1
11818
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 XmlNodeList. I am trying to deserialize the nodes using a foreach as follows: foreach(XmlNode lineItem in LineItemsNodeList) An abbreviated example of the nested lineItem node looks like this:
5
8373
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 method is normally used to convert a string to XML object. For Firefox I use E4X. For IE I use ActiveXObject loadXML() method. Thanks.
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9572
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10562
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10319
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10070
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9132
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.