Page 1 of 1

ActiveXObject or fload support

Posted: Tue May 15, 2007 2:42 am
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

Posted: Tue May 15, 2007 10:20 am
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.

Posted: Tue May 15, 2007 3:49 pm
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

Posted: Fri Jun 01, 2007 2:45 pm
by SweetRein
Any news on a possible xml or file parser? (Say yes, pretty please)

Posted: Fri Jun 01, 2007 3:53 pm
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

Posted: Fri Jun 01, 2007 4:58 pm
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]

Posted: Fri Jun 01, 2007 7:17 pm
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

Posted: Sat Jun 02, 2007 11:05 pm
by giliath
Great, glad I could help.