You would want to use XMLPrinter, as the Javadocs at the beginning of
the class state, if you have Jess code in a file, and need to parse
it and translate it to XML. That's not what you have here. Since you
already have the facts in working memory, it's actually just a one-
liner:
Rete engine = ...
// The "true" indicates XML output
engine.ppFacts(out, true);
If you need to do something trickier, you could use XMLVisitor in
that same package, something like
for(Iterator<Fact> i = rulePlugin.getFacts(); i.hasNext(); ) {
Fact f = i.next();
XMLVisitor v = new XMLVisitor(f);
out.println(v);
}
I would say the one-line version is better unless you need to insert
additional data into the printed text.
On Feb 28, 2007, at 12:37 AM, Hsin Terry Shen wrote:
Hi everyone,
New to the mailing-list, and new to Jess and Java. I'm currently
creating a web servlet that uses a Jess plug-in. I'm at the point
where I have the Jess facts, but would like to change the facts
into XML and then output it to PrintStream.
I've been trying for quite a while to figure this out (of course
it's really difficult because there's so little resources out
there), but am pretty much stuck. I have the only book about Jess
(Jess in Action), but the answer wasn't in there (as far as I can
tell, the book talks about using XSLT, and more about reading XML
into Jess, not outputing in XML). So, I thought I'd ask the expert
and fellow mailing-listers instead.
I'm trying to use the Class XMLPrinter listed on the website. This
is a snippet of the code so far, but basically, I can't get it to
work. Particularly, the translateToXML method. Please, help.
Thanks so much in advance. If anyone could point me to some code
example that has gotten the translateToXML method and XMLPrinter
class to work, that would be tremendously helpful.
~~Terry
----------------------------------------------------------------------
try {
ret = rulePlugin.evaluate("(facts)");
for(Iterator<Fact> i = rulePlugin.getFacts();
i.hasNext(); ) {
Fact f = i.next();
String facts = f.toString();
try {
FileReader reader = new FileReader (facts);
reader.translateToXML();
}
finally {
out.println(f.toString());
}
}
}
catch(Exception e) { e.printStackTrace(); }
}
/****/
------------------------------------------------------------
Hsin Yi (Terry) Shen, MSPH
NLM Predoctoral Fellow
Department of Medical Education and Biomedical Informatics
University of Washington
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users
[EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify owner-jess-
[EMAIL PROTECTED]
--------------------------------------------------------------------
---------------------------------------------------------
Ernest Friedman-Hill
Advanced Software Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://www.jessrules.com
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------