Forum Navigation
Add new elements to a Document after parse?
Moderators:
kris
Posted: 10/19/08 20:50:241. 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.