commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Baltz, Kenneth" <Kba...@firstam.com>
Subject RE: Digester Newbie Question
Date Thu, 06 Feb 2003 23:07:46 GMT
Digester 1.4 was released this week.  You might give it a try.  I don't see
anything immediately wrong with your example, but I'm not familiar with
using a validating parser or namespaces.  

K.C.

-----Original Message-----
From: Kim Scott [mailto:kims@cup.hp.com]
Sent: Thursday, February 06, 2003 2:02 PM
To: commons-user@jakarta.apache.org
Subject: Digester Newbie Question


Hi,

I am having a problem using digester 1.3 to parse element text.
Digester always returns the empty string for the element  text.  No
exceptions are thrown and the logging doesn't show any error messages.
Attributes work fine for me.  I tried digester 1.2 and then both work.
Does anyone have any suggestions on what could be going wrong when I try
1.3?  I'd like to use 1.3 so I can use a schema for validation.  The
code follows.

Thanks very much,
Kim

Here is the code.  I changed it to no longer set the schema when I
switched to 1.2.

    private static EmailContent parseEmailContent(String emailXmlString)
throws Exception
    {
      // Create reader for email xml string
      StringReader reader = new StringReader(emailXmlString);

      // Create digester
      Digester digester = new Digester();
      digester.setValidating(true);

      // Setup Parse Rules
      digester.addObjectCreate("Email", EmailContent.class);
      digester.addCallMethod("Email/Subject", "setSubject", 0);
      digester.addCallMethod("Email/Body", "setBodyText", 0);

      // Parse the configuration file
      EmailContent emailContent = (EmailContent)digester.parse(reader);

      return(emailContent);

    } // parseEmailContent

Here's a sample of the xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE Email SYSTEM "config/email.dtd">
<Email xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xsi:noNamespaceSchemaLocation='email.xsd'>
<Subject>
Critical Alert
</Subject>
<Body>
Oracle Financial System is impacting Order Flow.
</Body>
</Email>







---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message