RPTools.net

Discussion and Support

Skip to content

It is currently Thu Aug 17, 2017 8:25 pm 






Reply to topic  [ 8 posts ] 

Previous topic | Next topic 

  Print view

Author Message
 Offline
Kobold
 
Joined: Thu Apr 19, 2007 4:32 am
Posts: 18
 Post subject: ActiveXObject or fload support
PostPosted: Tue May 15, 2007 1:42 am 
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


Top
 Profile  
 
User avatar  Offline
RPTools Founder
 
Joined: Tue Jan 31, 2006 11:10 am
Posts: 277
Location: Austin, TX
 Post subject:
PostPosted: Tue May 15, 2007 9:20 am 
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


Top
 Profile  
 
 Offline
Kobold
 
Joined: Thu Apr 19, 2007 4:32 am
Posts: 18
 Post subject:
PostPosted: Tue May 15, 2007 2:49 pm 
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:
|?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


Top
 Profile  
 
 Offline
Kobold
 
Joined: Thu Apr 19, 2007 4:32 am
Posts: 18
 Post subject:
PostPosted: Fri Jun 01, 2007 1:45 pm 
Any news on a possible xml or file parser? (Say yes, pretty please)


Top
 Profile  
 
User avatar  Offline
RPTools Founder
 
Joined: Tue Jan 31, 2006 11:10 am
Posts: 277
Location: Austin, TX
 Post subject:
PostPosted: Fri Jun 01, 2007 2:53 pm 
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


Top
 Profile  
 
User avatar  Offline
RPTools Founder
 
Joined: Tue Jan 31, 2006 11:10 am
Posts: 277
Location: Austin, TX
 Post subject:
PostPosted: Fri Jun 01, 2007 3:58 pm 
I threw together a quick example.

Code:
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:
<?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


Top
 Profile  
 
 Offline
Kobold
 
Joined: Thu Apr 19, 2007 4:32 am
Posts: 18
 Post subject:
PostPosted: Fri Jun 01, 2007 6:17 pm 
Great! Thank you!
This almost works as is, except I had to remove
Code:
!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:
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


Top
 Profile  
 
User avatar  Offline
RPTools Founder
 
Joined: Tue Jan 31, 2006 11:10 am
Posts: 277
Location: Austin, TX
 Post subject:
PostPosted: Sat Jun 02, 2007 10:05 pm 
Great, glad I could help.

_________________
~Giliath


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 8 posts ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (based on users active over the past 5 minutes)
Most users ever online was 243 on Sun Nov 04, 2012 6:14 am

Users browsing this forum: No registered users and 1 guest





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman