Thank you so much for the response, I can't believe that the founder actually answers! I
have a follow-up question, though. The XML created with the XMLVisitor class isn't
well-formed. I need to add in CDATA sections and also there's one field that includes a
"<" character.
I can't find any good documentation on the XMLVisitor class on the website and
Google in general, and I've tried the visitFact method. Could somebody provide
some insight into how to solve this problem?
Here's a section of the XML to demonstrate what I'm referring to ->
-----------------------------------------------------------------------
<fact>
<name>MAIN::Population</name>
<slot>
<name>SourceID</name>
<value type='STRING'>639</value>
</slot>
<slot>
<name>Source</name>
<value type='STRING'></value>
</slot>
<slot>
<name>DBName</name>
<value type='SYMBOL'>dbSNP_Pop</value>
</slot>
<slot>
<name>ResourceObject</name>
<value
type='JAVA_OBJECT'><Java-Object:edu.washington.cs.db.browser.biomediator.BioMediatorResourceTable$BioMediatorResource></value>
</slot>
------------------------------------------------------------
Hsin Yi (Terry) Shen, MSPH
NLM Predoctoral Fellow
Department of Medical Education and Biomedical Informatics
School of Medicine, Box 357240
University of Washington
Seattle, WA 98195-7240
Lab Phone: 206-616-8414
[EMAIL PROTECTED]
http://students.washington.edu/hyshen
On Wed, 28 Feb 2007, Ernest Friedman-Hill wrote:
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 [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]
--------------------------------------------------------------------
--------------------------------------------------------------------
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]
--------------------------------------------------------------------