Ted Gress wrote:... I go to add the first root element...
Ted Gress wrote:Hi,
I'm having some trouble with JDOM2. I want to serialize my tree and I go to add the first root element and it says its already added to the document, but it's a new document I'm adding it to.
Code:
And my stack trace:
Ted Gress wrote:Hi,
I'm having some trouble with JDOM2. I want to serialize my tree and I go to add the first root element and it says its already added to the document, but it's a new document I'm adding it to.
Code:
And my stack trace:
Elliotte Rusty Harold wrote:In this case the document begins its life in a temporarily malformed state, and any attempt to do almost anything with it except set a root element or add content to the document’s prolog will fail
Ted Gress wrote:Same error as before:
Error:
[codejava]
187 In Class::class GameMap.XMLAdapter Journal Entry:Serializing root element: LevelRoot
Exception in thread "Thread-8" org.jdom2.IllegalAddException: The element "LevelRoot" could not be added as the root of the document: The Content already has an existing parent document
at org.jdom2.ContentList.checkPreConditions(ContentList.java:208)
at org.jdom2.ContentList.add(ContentList.java:244)
at org.jdom2.ContentList.add(ContentList.java:79)
at java.base/java.util.AbstractList.add(Unknown Source)
at org.jdom2.Document.setRootElement(Document.java:238)
at GameMap.XMLAdapter.Serialize(XMLAdapter.java:239)
at GameMap.CHotLoader.Serialize(CHotLoader.java:206)
at GameMap.CHotLoader.loadNMap(CHotLoader.java:132)
at GameMap.CHotLoader.loadMap(CHotLoader.java:115)
at GameMap.CHotLoader.HotLoad(CHotLoader.java:84)
at MainGame.Loop.run(Loop.java:29)
[/code]
David Simkulette wrote:It really seems to me that this is telling you that the element "LevelRoot" is already a part of a Document ( a Node can't be the child of two documents). Is there any way that that is possible?
Ted Gress wrote:Actually, you know what, it is adding RootOne. Its the next node down that it gives that LevelRoot error again.
Yeah, same thing. You have to add a copy of the element to the new tree
I was confused from the start, when you described your act of copying an XML document to another XML document as "serializing". The meaning of the word "serialize" in the XML world is to transform an internal representation of XML (e.g. a SceneGraphManager or a JDOM Document) to an external representation (a text file). The opposite transformation is called "parsing".
So as a result I found your complete code very hard to read because I didn't understand what its purpose was. It unfortunately became TL;DR. So could you give us a short summary of the purpose of that code?
Ted Gress wrote:
I was confused from the start, when you described your act of copying an XML document to another XML document as "serializing". The meaning of the word "serialize" in the XML world is to transform an internal representation of XML (e.g. a SceneGraphManager or a JDOM Document) to an external representation (a text file). The opposite transformation is called "parsing".
So as a result I found your complete code very hard to read because I didn't understand what its purpose was. It unfortunately became TL;DR. So could you give us a short summary of the purpose of that code?
That's the thing. The goal is to export the scenegraph to an xml file. So I am essentially serializing the SceneGraph to a text (xml) file.
What is TL;DR?
The purpose of the code is to first load each XML tag into a scenegraph, for example I may have a root tag that says "<LevelRoot>" and then a tag that says "<Loot>" and then a tag that says "<DaemonArmor>" nested within. I want to load those tags into SceneGraphNodes, with each node containing an XML Element like, for example, "<DaemonArmoir>" or "<Loot>".
The SceneGraph should be an exact mirror of the XML document loaded in.
Then, in the same class, but with different functionality, I want to serialize that scenegraph back to an XML file, basically reversing the process. So, since "<LevelRoot>" is the root node it should be that way in the XML file I'm outputting. Then, using the previous example, I want the next XML tag to be "<Loot>" and the following tag nested to be "<DaemonArmor>". So it should take the nodes in the SceneGraph and output them in order to an XML file.
Does that clarify things?
Ted Gress wrote:That's the thing. The goal is to export the scenegraph to an xml file. So I am essentially serializing the SceneGraph to a text (xml) file.
What is TL;DR?
Ted Gress wrote:I basically want to break down the JDOM2 tree that is loaded from the XML and build up a new Document for output
Ted Gress wrote:David,
In this case I don't think I can write a tiny program.
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|