ActiveXObject or fload support

Thoughts, Help, Feature Requests

Moderators: Azhrei, dorpond, giliath

Post Reply
SweetRein
Kobold
Posts: 18
Joined: Thu Apr 19, 2007 5:32 am

ActiveXObject or fload support

Post by SweetRein »

Does dicetools support ActiveXObject or another way to access local files [fload()] (of course, with dicetools running off of the computer itself)?

ActiveXObject would make handling xml character sheets a breeze. fload would take a bit of testing and work, but could also do it.

If there is no equivalent, may I request for these to be added?
-
This is, of course, for functions.js

User avatar
giliath
RPTools Founder
Posts: 275
Joined: Tue Jan 31, 2006 11:10 am
Location: Austin, TX
Contact:

Post by giliath »

No, DiceTool does not currently support accessing ActiveX objects. It does however support everything that is possible in Java. The engine we are currently using is called "Rhino" and information about it is available here: http://www.mozilla.org/rhino/.

Tell me a little more about what you are trying to do with it and lets see if we can figure out an alternate way.
~Giliath

SweetRein
Kobold
Posts: 18
Joined: Thu Apr 19, 2007 5:32 am

Post by SweetRein »

I wish to load an xml document using a javascript function. More specifically, if possible, pull child information from nodes or just get based on xml node names.
Here's the xml document (an rpgwebprofiler 3E profile document) (Purr.xml)

Code: Select all

|?xml version="1.0" encoding="iso-8859-1"?>
|!DOCTYPE character PUBLIC "-//rpgprofiler.net//DTD 3EProfiler 1.0//EN"
  "http://www.rpgprofiler.net/2003/3EProfiler.dtd">
|character xmlns="http://www.rpgprofiler.net/2003/3EProfiler">
  <source>...edited out...</source>
  <cname>Purr</cname>
  <template>d20 v3.5 DnD</template>
  <public>y</public>
  <data>
    |node name="firstload">false</node>
    ...(various other unimportant nodes)...
    |node name="Str">14</node>

(replace | with <, cause the code on phpbb want to remove a lot of information from tags...)


My end goal is for the ability to do the following in DiceTools:
GetXml('Purr.xml','Str') to produce 14

SweetRein
Kobold
Posts: 18
Joined: Thu Apr 19, 2007 5:32 am

Post by SweetRein »

Any news on a possible xml or file parser? (Say yes, pretty please)

User avatar
giliath
RPTools Founder
Posts: 275
Joined: Tue Jan 31, 2006 11:10 am
Location: Austin, TX
Contact:

Post by giliath »

This should be possible using a combination of JAXP and XPath that is built into Java 1.5.

Here are some references that should lead you down the right path.

http://java.sun.com/developer/technical ... tionxpath/
http://www.mozilla.org/rhino/scriptjava.html
~Giliath

User avatar
giliath
RPTools Founder
Posts: 275
Joined: Tue Jan 31, 2006 11:10 am
Location: Austin, TX
Contact:

Post by giliath »

I threw together a quick example.

Code: Select all

function testJava(statName) {
   var builder = Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder();
   var doc = builder.parse(new java.io.File("test01.xml"));
   var xpath = Packages.javax.xml.xpath.XPathFactory.newInstance().newXPath();
   
   row.setLabel(xpath.evaluate("/character/name", doc, Packages.javax.xml.xpath.XPathConstants.STRING));
   
   var value = xpath.evaluate("/character/stats/stat[@name='" + statName + "']", doc, Packages.javax.xml.xpath.XPathConstants.NUMBER);
   java.lang.System.out.println(value);
   
   return value;
}



Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<character>
  <name>Giliath</name>
  <stats>
     <stat name="Str">10</stat>
     <stat name="Con">11</stat>
     <stat name="Dex">12</stat>
     <stat name="Int">13</stat>
     <stat name="Wis">14</stat>
     <stat name="Chr">15</stat>
  </stats>
</character>
[/quote]
~Giliath

SweetRein
Kobold
Posts: 18
Joined: Thu Apr 19, 2007 5:32 am

Post by SweetRein »

Great! Thank you!
This almost works as is, except I had to remove

Code: Select all

!DOCTYPE character PUBLIC "-//rpgprofiler.net//DTD 3EProfiler 1.0//EN"
  "http://www.rpgprofiler.net/2003/3EProfiler.dtd"

and
the notes sections from the RPG Profiler files.
After that, worked well! I am using now:

Code: Select all

function getx(Cn,Cf) {
   var builder = Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder();
   var doc = builder.parse(new java.io.File(Cf + ".xml"));
   var xpath = Packages.javax.xml.xpath.XPathFactory.newInstance().newXPath();
   
   return xpath.evaluate("/character/data/node[@name='" + Cn + "']", doc, Packages.javax.xml.xpath.XPathConstants.NUMBER);;
}

so, I could use.. say..
getx("Int","Purr") to get Int from Purr.xml

User avatar
giliath
RPTools Founder
Posts: 275
Joined: Tue Jan 31, 2006 11:10 am
Location: Austin, TX
Contact:

Post by giliath »

Great, glad I could help.
~Giliath

Post Reply

Return to “DiceTool”