• Post Reply Bookmark Topic Watch Topic
  • New Topic

Convert tree information to a list  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a tree data structure which contains info like below


root node is 1 which contains 3 children nodes [2a, 2b, 2c]
each child node at the second level in turns contains variant child nodes. For instance, 2a contains [3aa, 3ab], 2b contains [3ac], and 2c contains [3ad, 3ae].

Now I want to convert these values in tree to list. So the result may look like


What  would a good way to achieve this? Thanks in hint, advises and suggestions.
 
Marshal
Posts: 4216
248
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello John, welcome to the Ranch!

What does the original data structure look like in Java?
 
John Todd
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Cooke wrote:Hello John, welcome to the Ranch!

What does the original data structure look like in Java?



It's xsd files and I am already able to extract those information using apache ws xmlschema lib. The output read from those xsd structure is basically in DFS fashion so it looks like in a form of tree as posted in the original question (where print out goes from 1 -> 2a -> 3aa and 3ab; then 2b -> 3ac, and so on).    
 
Tim Cooke
Marshal
Posts: 4216
248
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've extracted your data from the XSD file and now have something in Java. What is the Java type that holds the data?
 
John Todd
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Cooke wrote:You've extracted your data from the XSD file and now have something in Java. What is the Java type that holds the data?



The Java type that holds the data are String.
 
Tim Cooke
Marshal
Posts: 4216
248
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All of that XSD file extraction with the Apache library resulted in just a single String? Really? I'm surprised, and suspicious that is not the case. I would have expected it to have organised it into some sort of Collection type.
 
John Todd
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Cooke wrote:All of that XSD file extraction with the Apache library resulted in just a single String? Really? I'm surprised, and suspicious that is not the case. I would have expected it to have organised it into some sort of Collection type.



I probably misunderstand your question. The data type extracted by library includde XmlSchemaElement, XmlSchemaComplexType, XmlSchemaSimpleType, and XmlSchemaAttribute. And the target values I am looking for (and are extracted) are String. For instance, <xs:element name="2a"> where my target is 2a whose type is String. So does the value for the tag <xs:attribute name="3aa"> where extracted 3aa is the attribute value whose type is String as well.
 
Tim Cooke
Marshal
Posts: 4216
248
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show the code you have so far?
 
John Todd
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Cooke wrote:Can you show the code you have so far?



Ok. I think I solve the problem. Basically I was thinking too much. Instead of trying to use another structure in capturing all information, simply record the current depth, current prefix, and with a collector like map(prefix, attributes) do accomplish the goal. The code is tightly couple together so here I only show the logic that works. Apologize if that's still too abstract.



Thanks for help and suggestions. Much appreciated!
 
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!