XML config library - Added github

Discussion in 'Resources' started by microgeek, Apr 2, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    microgeek

    GITHUB: https://github.com/microgeek/XMLConfig

    I've started on this, and it's coming along nicely. It's essentially mirroring the configuration Api in XML, but it's much more flexible. For example, you can easily serialize and de-serialze ItemStacks, Locations, and more. Syntax for saving a location and itemstack:

    HTML:
    <item type="location" key="location_1">
        <item key="world" value="world_nether" />
        <item key="x" value="90" />
        <item key="y" value="90" />
        <item key="z" value="90" />
        <item key="pitch" value="70" />
        <item key="yaw" value="50" />
    </item>
     
    <item type="itemstack" key="itemstack_1">
        <item key="material" value="STICK" />
        <item key="meta">
            <item key="type" value="unspecific" />
            <item key="display-name" value="&lA stick" />
            <item key="lore">
                <item value="lore1" />
                <item value="lore2" />
            </item>
        </item>
    </item>
    
    Loading them:
    PHP:
    XMLConfig xc XMLConfigUtilities.getConfig("testConfig");
    Location location xc.getLocation("location_1");
    ItemStack itemstack xc.getItemStack("itemstack_1");
    If you do not want to call the method getLocation, getString, ect, you can just call get, and it will parse it into the best choice, and cast it into an Object.
    PHP:
    XMLConfig xc XMLConfigUtilities.getConfig("testConfig");
    Location location = (Locationxc.get("location_1");
    Feedback?


    Status:
    Finishing reading/parsing primitive types

    Todo:
    Add saving
    Clean up code a bit
     
  2. Offline

    macguy8

    I like what you're doing a lot, but why do you prefer XML over YML? I get its more flexible in storing locations, itemstacks, etc, but that's all possible with YML also.
     
  3. Offline

    microgeek

    For a two(main) reasons.
    1. XML is not dependent on indentation
    2. Allows for more flexibility, such as adding attributes or "meta" values to lists, and other datatypes, but still allows for a path.to.value navigation
     
    stirante and bobacadodl like this.
  4. Offline

    bobacadodl

    Yes, please!
     
  5. can you make it implement FIleCOnfiguration for easy changing our codes
     
  6. Offline

    stirante

    I'd love to use it! Looks awesome :D
     
    microgeek likes this.
  7. Offline

    microgeek

    ferrybig
    It's as simple as making an instance of the XMLConfig, calling xmlconfig.set(path.to.value, value), and to retrive it, you just call xmlconfig.get<DataType(Integer, Location, String, ect.)>(path.to.value)
     
  8. Offline

    stirante

    When you plan to release it? (Can't wait :)) Also this allows for storing more objects like HashMaps or PotionEffects. I hope it will be on github so maybe i'll try to make it better (if it's possible(oh, and i don't mean copy, change author name and compile but PR ofc)).
     
  9. Offline

    microgeek

    Of course, I love GitHub(I rarely use it though =/)!
    I'm not 100% sure when the release is going to be, but within a few days I hope! I need to add options for parsing certain data types(such as lists and maps), and I need to add saving of the files also(should not be too hard ;)). I'll be sure to update the thread with status updates.

    Here is a small part of the main file, for pasring and getting values:

    Code:java
    1.  
    2. public String getNodePath(Node node) {
    3. String path = getNodeKey(node);
    4. Node parent = node.getParentNode();
    5. while(parent != null && getNodeKey(parent) != null) {
    6. path = getNodeKey(parent) + "." + path;
    7. parent = parent.getParentNode();
    8. }
    9. return path;
    10. }
    11.  
    12. public String getNodeType(Node node) {
    13. return getNodeAttribute(node, "type");
    14. }
    15.  
    16. public String getNodeKey(Node node) {
    17. return getNodeAttribute(node, "key");
    18. }
    19.  
    20. public String getNodeValue(Node node) {
    21. String attribute = getNodeAttribute(node, "value");
    22. if(attribute != null) return attribute;
    23. return node.getTextContent();
    24. }
    25.  
    26. public String getNodeAttribute(Node node, String attribute) {
    27. if(node == null) return null;
    28. if(node.getAttributes() == null) return null;
    29. Node value = node.getAttributes().getNamedItem(attribute);
    30. if(value == null) return null;
    31. return value.getTextContent();
    32. }
    33.  
    34. public List<Node> getAllNodes() {
    35. List<Node> nodes = new ArrayList<Node>();
    36. for(Node n : nodeListToList(document.getChildNodes())) {
    37. nodes.addAll(getChildNodes(n));
    38. }
    39. return nodes;
    40. }
    41.  
    42. public List<Node> getChildNodes(Node node) {
    43. List<Node> nodes = new ArrayList<Node>();
    44. nodes.add(node);
    45. for(Node n : nodeListToList(node.getChildNodes())) {
    46. nodes.addAll(getChildNodes(n));
    47. }
    48. return nodes;
    49. }
    50.  
    51. public List<Node> nodeListToList(NodeList nodeList) {
    52. List<Node> nodes = new ArrayList<Node>();
    53. for(int i = 0; i < nodeList.getLength(); i++) {
    54. Node n = nodeList.item(i);
    55. if(n.getNodeType() == Node.TEXT_NODE) continue;
    56. nodes.add(n);
    57. }
    58. return nodes;
    59. }


    Sorry about the indentation =/

    I've got parsing of all primitive types, plus locations. I need to do Collections, maps, so then I can add support for itemstacks, potion effectes, ect.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
    stirante likes this.
  10. Offline

    stirante

    Will it have simple api for storing other objects? For example i'm creating some magic plugin and I want to store object MagicPlayer which contains 5 simple vars. Will it be able?
     
  11. Offline

    microgeek

    Yes, it will be quite easy to do so.
    You can easily write your own method, like how I did the Locations:
    Code:
        public Location getLocation(String path) {
            World world = plugin.getServer().getWorld(getString(addPath(path, "world")));
            double x = getDouble(addPath(path, "x"));
            double y = getDouble(addPath(path, "y"));
            double z = getDouble(addPath(path, "z"));
            float yaw = getFloat(addPath(path, "yaw"));
            float pitch = getFloat(addPath(path, "pitch"));
            return new Location(world, x, y, z, yaw, pitch);
        }
        
     
    stirante likes this.
  12. Offline

    stirante

    microgeek
    I know you could be busy but I wanted to use this lib in one of my newest projects so at least I expect status update like "I won't finish it" or anything.
     
  13. Offline

    ohtwo

    I think it's a better idea to not expect anything.
     
  14. Offline

    stirante

    I mean i'm wating with project for this library so if it won't be finished i'll have to continue project but using yml.
     
  15. Offline

    microgeek

    I've had 4 custom plugin(quite large) jobs to finish, but I do plan to release this, it might be a week or so.
     
    stirante and ohtwo like this.
  16. Offline

    JazzaG

    Any chance we could see this on GitHub before its release?
     
  17. Offline

    stirante

    microgeek
    Is there any chance it will be released?
     
  18. Offline

    skipperguy12

    I REALLY need this, it looks amazing! What you're doing is just amazing! Thank you!
     
  19. Offline

    stirante

    Sorry, but it's inactive since beggining of april :(
     
  20. Offline

    skipperguy12

    stirante
    Dang, someone needs to make this. Want to work with me on making a new one of these?
     
  21. Offline

    Skyshayde

    I would be willing to help, I don't know a ton of java though.
     
  22. Offline

    microgeek

    I don't know when I'll be able to finish this, so I'm throwing what I have on GitHub, feel free to make PRs, give me a few minutes.

    Just cleaning up some code and adding a few things, expect first commit in about 30 minutes.

    Added to github, enjoy I guess.
    https://github.com/microgeek/XMLConfig

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  23. Offline

    microgeek

    Deciding to pick this back up. I've done a lot of work, and I almost have reading values completely done. setting values and saving them are a bit harder, but I plan on getting it working.
     
  24. Offline

    skipperguy12

    I figured out how to do this, without a lib. Just search up a basic tutorial of JDOM2, and it's really easy, unlike SAX and DOM (it's just a combination of both, but easier to use)
     
  25. Offline

    microgeek

    This is more of a mirror of yamlsnake but with XML, more user friendly and removes redundant and repetitive code.
     
  26. Offline

    Ultimate_n00b

    Hm, I think I may use this.
     
  27. Offline

    microgeek

    I try to work on it, to get it to a fully working and dev friendly state, but there's a lot of work that still needs to be done. Feel free to contribute to the GitHub.
     
Thread Status:
Not open for further replies.

Share This Page