Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Add new elements to a Document after parse?

Moderators: kris

Posted: 10/19/08 20:50:24

1. Am I missing something or can't I add a new element to a Document after I called the parse method? For example:

auto = new Document!(char);
doc.parse(content);

doc.root.element(null, "element", "value");
auto = new Document!(char);

auto node = doc.root.element(null, "element1", "value1");
node.element(null, "element2", "value2");

Both of the above examples work but not the following code:

auto = new Document!(char);
doc.parse(content);

doc.root.firstChild.element(null, "element", "value");

Nothing happens in the above code, there is no new element attached to the node.

2.

auto = new Document!(char);
doc.parse(content);

doc.query["rss"]["channel"]["webMaster"].nodes[0].value = "doob";

The above code adds "doob" to the webMaster element instead of replacing the value.

3. I think the API in NodeSet could be a little better to access the nodes. For example: the methods "first", "last", "opIndex" and "nth" all return a NodeSet with one single node instead of returning a Node. The only way to access the actual nodes is using the field "nodes" which isn't documented.

Author Message

Posted: 10/22/08 16:54:16

I suspect the latest SVN may fix the missing elements (there was a bug in the XmlPrinter?). Could you see if that fixes the issue, please?

Posted: 10/22/08 21:58:53

I updated to the latest SVN revision now and that solved nr 1. but not nr 2.

Posted: 10/23/08 03:03:20

k, thanks ... will get on it tomorrow :)

Posted: 10/23/08 09:52:56

thanks