-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inserting nodes into a tree #51
Comments
Same question here. |
|
Well, I just added the nodes as raw objects to the existing tree and it worked so far. Anything more complex would require the node objects to have common ancestor. |
Is there still an interest in this? For a project I am working on I had to add a parent attribute to nodes so I could walk back up the tree after finding a node. So basically this:
I also had to start to implement some additional functions for manipulating the XML doc with additional methods for the XmlElement, such as prependChild, appendChild, insertBefore, insertAfter, etc.. I tried to stick close to XML DOM as it ends up with more portable code if someone switches to a browser based JS object for XML. Edit: Though I would be happy to deviate from, or expand upon, the spec, with functions like |
I think lots of folks would be happy to see mutability! I think using the spec for inspiration is good since one can carryover their possible knowledge from XML DOM, but I don't think it's necessary to confirm to the spec since the rest of this library doesn't already. And helpful things like |
So, I have this working minus one key aspect, which is what to do with a few properties that are set for each element when the document is parsed and then manipulated. These would be:
My gut would be to invalidate those values once the XML tree has been modified as at that point you are no longer dealing with the original string that was passed to the parser, but really a nested group of objects. Alternatively, if we wanted to maintain those and not destroy them we could add an option to the creation function of an XmlDocument, such as:
For xml documents that are modifiable we could always drop the |
You can track the progress on this branch: https://github.com/aleph1/xmldoc/tree/aleph1-node-manipulation |
Well, I'm not sure that invalidating the values "as you go" is going to be great because once you modify the tree, it could have a cascading effect on all elements in the tree. So you'd really have to invalidate the whole tree. I think your idea of an option in this case is good - but I'd actually make it If you do pass the What do you think? |
|
I'd say let's roll with it in this branch because it feels correct - and when it's ready to merge we can make the call on whether enough other stuff has changed/improved that it warrants a major version bump. |
One other related question. Currently
Whereas this one will pass:
This can be resolved by having |
More updates have been made on that branch. A few notes:
The only glaring issue is going to be how we handle cases where there is an attempt to append an XmlDocument to an XmlElement. In theory this is possible, but it gets weird if someone has created the two XmlDocuments with different settings. Since we can’t detach nodes from a document that is readonly, I am proposing I also add a For example:
|
I've added the following to this branch: https://github.com/aleph1/xmldoc/tree/aleph1-node-manipulation
A few more comments and questions:
|
This is all fantastic. My thoughts:
|
I am aiming to have these changes in place by next week. |
|
Is there any intention to merge this mutable functionality into the main branch? |
How would I insert another node into this tree?
The text was updated successfully, but these errors were encountered: