Simon, Thanks a lot for your tips...
Using custom Rule suggested in your email does solve the problem for me... Thanks, - michelle --- Simon Kitching <[EMAIL PROTECTED]> wrote: > On Thu, 2006-03-02 at 18:16 -0800, Michelle Lin > wrote: > > Digester Experts: > > > > I have the following simple XML doc: > > > > <?xml version="1.0" encoding="ASCII"?> > > <xyz xmlns="http://mynamespace" > > xmlns:xsd="http://www.w3.org/2001/XMLSchema"> > > <property name="a" type="xsd:string"/> > > </xyz> > > > > How can I use the digester to parse this XML doc > and > > get the value of "type" attribute as QName of: > > namespace: "http://www.w3.org/2001/XMLSchema" > > prefix: "xsd" > > localPart: "string" > > > > Any suggestions/pointers are very much > appreciated. > > Method Digester.findNamespaceURI can map from the > string "xsd" to the > associated URI. > > In order to call it at the correct time I would > recommend creating a > custom Rule. eg: > > // when this rule fires, if the current element has > an attribute > // of the specified name, then it is assumed to be a > prefix:ename > // pair. It is converted into a QName object and > passed to a bean > // property (specified by propName) on the top > object on the > // digester stack > > public class SetQNameRule extends Rule { > private String attrName; > private String propName; > > public SetQNameRule(String attrName, String > propName) { > this.attrName = attrName; > this.propName = propName; > } > > public void begin(namespace, name, Attributes > attrs) { > // get attribute with name this.attrName > // split it on ':' char > // call digester.findNamespaceURI to convert > prefix to URI > // create QName object > // > // get top object on digester stack > // Use BeanUtils to assign the qname to its > propName property > } > } > > The above is basically a simplified version of > CallMethodRule. > > As an alternative, create a Rule based on > CallParamRule. Of course > you'll then need to use your rule in combination > with a CallMethodRule. > > Another alternative would be to register a custom > (String->QName) > converter with the BeanUtils framework. That's a bit > scary though as the > converter needs a reference back to the Digester > instance in order to > map prefix->URI but BeanUtils converters are > effectively "global". If > you've got a multithreaded app things could go badly > wrong. > > Hope this helps. > > Regards, > > Simon > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: > [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] > > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
