Background
I'm currently working on a program that can
- Construct Directory: traverses a directory and store the "tree" as JSON/XML,
- Deconstruct Directory: read in a JSON/XML file that contains a directory "tree" and builds the directory
- Display Directory: print (to stdout) the directory in a typical tree format
My question is regarding the most efficient way to construct/deconstruct a directory.
Question 1
I currently have two formats for the JSON/XML files (see examples at bottom). The first format is minimalist and the second is more robust.
Is there a particular format that I should use (i.e. provide the minimal amount of data required in a file), along with a more efficient function to construct/deconstruct the directories?
Will one work better with JSON than with XML or vise versa?
Known Issues
- XML does not support empty strings, while JSON does. This yields NONE values during construction, when using XML files.
- Format 1 of the XML cannot distinguish between and empty folder and a file.
Note
If you would like me to clarify or provide more info, please let me know. Thanks
Format 1
{ "parent":{ "child_1":{ "grandchild_1a":{ "file_1a1":"" } }, "child_2":{ "grandchild_2a":{ "file_2a1":"", "file_2a2":"" }, "grandchild_2b":{ "file_2b1":"" }, "grandchild_2c":{ } } } } <?xml version="1.0" encoding="utf-8"?> <parent> <child_1> <grandchild_1a> <file_1a1> </file_1a1> </grandchild_1a> </child_1> <child_2> <grandchild_2a> <file_2a2> </file_2a2> <file_2a1> </file_2a1> </grandchild_2a> <grandchild_2b> <file_2b1> </file_2b1> </grandchild_2b> <grandchild_2c> </grandchild_2c> </child_2> </parent> Format 2
{ "explicit_path":{ "name": "parent", "type": "folder", "path": "/parent", "contents": [ { "name": "child_1", "type": "folder", "path": "/parent/child_1", "contents": [ { "name": "grandchild_1a", "type": "folder", "path": "/parent/child1/grandchild_1a", "contents": [ { "name": "file_1a1", "type": "file", "path": "/parent/child_2/grandchild_1a/file_1a1" } ] } ] }, { "name": "child_2", "type": "folder", "path": "/parent/child_2", "contents": [ { "name": "grandchild_2a", "type": "folder", "path": "/parent/child_2/grandchild_2a", "contents": [ { "name": "file_2a1", "type": "file", "path": "/parent/child_2/grandchild_2a/file_2a1" }, { "name": "file_2a2", "type": "file", "path": "/parent/child_2/grandchild_2a/file_2a2" } ] }, { "name": "grandchild_2b", "type": "folder", "path": "/parent/child_2/grandchild_2b", "contents": [ { "name": "file_2b1", "type": "file", "path": "/parent/child_2/grandchild_2b/file_2b1" } ] }, { "name": "grandchild_2c", "type": "folder", "path": "/parent/child_2/grandchild_2c", "contents": [ ] } ] } ] } } <?xml version="1.0" encoding="utf-8"?> <explicit_path> <path>/parent</path> <type>folder</type> <name>parent</name> <contents> <path>/parent/child_1</path> <type>folder</type> <name>child_1</name> <contents> <path>/parent/child1/grandchild_1a</path> <type>folder</type> <name>grandchild_1a</name> <contents> <path>/parent/child_2/grandchild_1a/file_1a1</path> <type>file</type> <name>file_1a1</name> </contents> </contents> </contents> <contents> <path>/parent/child_2</path> <type>folder</type> <name>child_2</name> <contents> <path>/parent/child_2/grandchild_2a</path> <type>folder</type> <name>grandchild_2a</name> <contents> <path>/parent/child_2/grandchild_2a/file_2a1</path> <type>file</type> <name>file_2a1</name> </contents> <contents> <path>/parent/child_2/grandchild_2a/file_2a2</path> <type>file</type> <name>file_2a2</name> </contents> </contents> <contents> <path>/parent/child_2/grandchild_2b</path> <type>folder</type> <name>grandchild_2b</name> <contents> <path>/parent/child_2/grandchild_2b/file_2b1</path> <type>file</type> <name>file_2b1</name> </contents> </contents> <contents> <path>/parent/child_2/grandchild_2c</path> <type>folder</type> <name>grandchild_2c</name> </contents> </contents> </explicit_path>
No comments:
Post a Comment