XmlHandler - TahliaK/wight-whale GitHub Wiki

XmlHandler provides a simple method for reading and writing in XML any appropriately annotated Java class.

Appropriate annotation looks something like this:

import javax.xml.bind.annotation.*;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement

public class Foo {
    @XmlElement (name = "someName")
    private int field;
}

There are 3 methods/tasks:

  1. Create the XmlHandler for your class

XmlHandler<Bar> handler = new XmlHandler<Bar>(new Bar().getClass());

  1. Use it to read from your file (in the "Files/" directory)

Bar barObj = handler.readFromXml("directory", "filename.extension")

  1. Use it to write to a file (in the "Generated/" directory)

handler.writeToXml(barObj, "directory", "Bar_ID");

Notes:

  • The constructor can fail. If it does, it will use Log.send(ERROR...)
  • You can check in-program if the xmlHandler is functioning with the status() function
  • If the constructor failed, nothing will execute and all returns will be null
  • Ouputs go to "[Project file]/Generated/[directory]/[itemId].xml".
  • Inputs are searched for in "[Project file]/Files/[directory]/[filename]" (Note that ".xml" extension is NOT included in inputs)
  • [directory] variables are optional; to use the root in/out folder, enter "" for directory.
⚠️ **GitHub.com Fallback** ⚠️