-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
How to insert document as node into another DOM tree? #366
Comments
The example code may have problem that two I think your first solution is better, because it states that the address document contains the To prevent the life-cycle issue, you can deep-clone the value in Value addressValue = Value(addres["address"], person.GetAllocator());
person["person"].AddMember("address", addressValue, person.GetAllocator()); Or, to prevent the deep-cloning, you can use the same allocator for both Documnet address(person.GetAllocator());
// ... |
@miloyip Thanks for the explanation and pointing at the possible issues, very informative. |
Note that the recommendation above to use the same allocator in the second document has a small typo. You must pass the allocator as a pointer: Document address(&person.GetAllocator()); |
Let's take two
Document
objects created by parsing the following .json files:What is the best way to insert the whole "address" node into the "person" DOM tree as a sibling node of the "name"?
So, the final document it reads
Here is code that creates instances of the two DOM trees:
followed by two possible solutions I was able to come up with:
Requires to know name of the node in the source DOM - inconvenient, impractical:
Requires use of iterators - not bad, but don't feel like suitable tool in this context:
Is there another, better way to achieve the same?
The text was updated successfully, but these errors were encountered: