Developers, Developers, Developers! Maksim Sorokin IT Blog

1Mar/11Off

Reading XML File in Custom IzPack Panel

Sometimes it is needed to have some configuration file in your custom IzPack panels. It is easy to have one!

First, you have to reference your configuration file from resources section in install.xml file:

<resources>
  <res id="mySpec.xml" src="mySpec.xml" />
</resources>

Then you would need to create such file in your IzPack resources.

And then you can read your file from your custom panel:

@Override
public void panelActivate() {
  InputStream is = ResourceManager.getInstance().getInputStream("mySpec.xml");
...

Moreover, you can read xml using IzPack capabilities. Not that convenient, but anyway:

    String xml = inputStreamToString(is);    // I omit this peace of code, since it is not relevant. "is" -- is InputStream

    IXMLParser parser = new XMLParser();
    IXMLElement rootEl = parser.parse(xml);

    Vector<IXMLElement> els = rootEl.getChildrenNamed("myElements");
    Iterator<IXMLElement> it = els.iterator();
    while (it.hasNext()) {
      IXMLElement el = it.next();

      String myAttribute = el.getAttribute("myAttribute");
      ...
Comments (2) Trackbacks (0)

Leave a comment


Trackbacks are disabled.