Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Beans > Re: Why my xml ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 1252 of 1401
Post > Topic >>

Re: Why my xml file could be parsed in main method, but not in the backing bean method?

by "Þór Sigurðsson" <thor@[EMAIL PROTECTED] > Nov 18, 2006 at 01:11 PM

Do you have a DTD for your XML file ?

Even if the XML file is syntactically correct, it's still invalid if you 
don't include a DTD..

"jacksu" <jacksuyu@[EMAIL PROTECTED]
> wrote in message 
news:1162002117.392146.283790@[EMAIL PROTECTED]
> Hi,
> I created a Email Template. Using
> org.apache.commons.digester.Digester to parse my email.xml ---
> <email>
>    <from>someone@[EMAIL PROTECTED]
>
>    <to>somebody@[EMAIL PROTECTED]
>    <subject>Hello,</subject>
>    <body> Hello {0} from {1 }</body>
> </email>
>
> When I tested it in the main method below. It works good.
> public class DigesterDriver {
>
>    public static void main( String[] args ) {
>
>        try {
>            Digester digester = new Digester();
>            digester.setValidating(false);
>
>            digester.addObjectCreate("email", EmailTemplate.class);
>
>            digester.addBeanPropertySetter("email/subject", "subject");
>            digester.addBeanPropertySetter("email/body", "body");
>            digester.addBeanPropertySetter("email/from", "from");
>
> //Sorry, the three lines below not parsed correctly so far.
> //            digester.addCallMethod("email/to", "addTo", 0);
> //            digester.addCallMethod("email/cc", "addCc", 0);
> //            digester.addCallMethod("email/bcc", "addBcc", 0);
>
>            File input = new File( "C:\\requestInfoEmail.xml" );
>
>            EmailTemplate et = (EmailTemplate)digester.parse(input);
>            String[] arg = {" peter ", "zhang"};
>            String body = MessageFormat.format(et.getBody(),
> (Object[])arg);
>            System.out.println("subject: " + et.getSubject());
>            System.out.println("body: " + body);
>            System.out.println("from: " + et.getFrom());
>
>        } catch( Exception exc ) {
>            exc.printStackTrace();
>        }
>    }
> }
>
> I could get some print out.
>
> But the exactly same thing used in backing bean method. It didn't work.
> digester.parse(input) always return a null. And the error is it could
> not recognize the
> <email> in the xml file. So it couldn't parse it.
> By the way, this backing bean method is invoked when someone request
> some infomation, it send a email to the info dept.
>
> Why? It is weird.
>
 




 2 Posts in Topic:
Why my xml file could be parsed in main method, but not in the b
"jacksu" <ja  2006-10-27 19:21:57 
Re: Why my xml file could be parsed in main method, but not in t
"Þór Sigurðsson"  2006-11-18 13:11:16 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 12:05:13 CST 2008.