-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

All,

I've built a pair of unit tests which I think should pass. The
"namespacePrefix" one fails.

Any help with this would be appreciated. It's entirelyentierly
possible that I'm missing some obvious concept or setting of the digeste
r.

The "config" method probably does things that are unnecessary -- such
as setting the various XML parsing features. But I wanted this to
mirror as closely as possible the situation in my application.

Thanks,
- -chris

=== CUT ===

    @Test
    public void testXMLParsing() throws Exception {
        testXMLParsing("<list xmlns=\"http://apache.org/test\";>"
                + "<element>foo</element>"
                + "</list>");
    }

    @Test
    public void testNamespacePrefixedXMLParsing() throws Exception {
        testXMLParsing("<ns:list xmlns:ns=\"http://apache.org/test\";>"
                + "<ns:element>foo</ns:element>"
                + "</ns:list>");
    }

    private void testXMLParsing(String xml) throws Exception {
        Digester digester = config(new Digester());

        ArrayList<String> list = new ArrayList<String>();
        digester.push(list);

        digester.addCallMethod("list/element", "add", 1, new Class[] {
Object.class });
        digester.addCallParam("list/element", 0);

        digester.parse(new StringReader(xml));

        Assert.assertEquals(1,  list.size());
        Assert.assertEquals("foo", list.get(0));
    }

    private Digester config(Digester digester) throws SAXException {
        try {

digester.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);

digester.setFeature("http://xml.org/sax/features/external-general-entiti
es",
false);

digester.setFeature("http://xml.org/sax/features/external-parameter-enti
ties",
false);

digester.setFeature("http://apache.org/xml/features/disallow-doctype-dec
l",
true);
        } catch (ParserConfigurationException pce) {
            throw new SAXException("Cannot enable parser feature", pce);
        }

        digester.setRuleNamespaceURI("http://apache.org/test";);
        digester.setNamespaceAware(true);
        digester.setValidating(false);

        return digester;
    }


=== CUT ===

On 2/14/20 12:04, Christopher Schultz wrote:
> All,
>
> I'm having an odd problem which I'm not sure I've seen before. I
> *think* I'm doing everything correctly, but I'm not getting the
> behavior I expect.
>
> I'm trying to parse an XML document using digester 3.2. My code
> looks like this:
>
> Digester digester = new Digester();
>
> try {
>
> digester.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
>
> digester.setFeature("http://xml.org/sax/features/external-general-enti
ti
>
>
es",
> false);
>
> digester.setFeature("http://xml.org/sax/features/external-parameter-en
ti
>
>
ties",
> false);
>
> digester.setFeature("http://apache.org/xml/features/disallow-doctype-d
ec
>
>
l",
> true); } catch (ParserConfigurationException pce) { throw new
> SAXException("Cannot enable parser feature", pce); }
>
> digester.setRuleNamespaceURI("my-namespace-URI");
> digester.setNamespaceAware(true); digester.setValidating(false);
>
> MyTopLevelBean bean = new MyTopLevelBean(); digester.push(bean);
>
> digester.add[Whatever]("path/without/namespace/prefix", ...); [...
> other rule additions ...]
>
> digester.parse(xmlInput);
>
> When I run this with an XML document with no namespace prefix but
> with a namespace matching the one I have in the code:
>
> <document xmlns="my-namespace-URI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> xsi:namespaceLocation="my-namespace-URI
> http://my/namespace/schema.xsd";> <sample-value>foo</sample-value>
> </document>
>
> All works as expected. But if I modify the document to include a
> namespace prefix:
>
> <foo:document xmlns:foo="my-namespace-URI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> xsi:namespaceLocation="my-namespace-URI
> http://my/namespace/schema.xsd";>
> <foo:sample-value>foo</foo:sample-value> </foo:document>
>
> I don't get any errors, but none of my rules fire and I get no
> data coming out of the document. The code is identical.
>
> Am I overlooking something very obvious?
>
> -chris
>
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl5IP4wACgkQHPApP6U8
pFgSDRAAxYfJqPJ3YKiISLbPX0JgtIyD3o3NeFdimXQVMdduHif6aO+W8oHzOfWN
/OejhyGpwcdgVXbyot7kvyNGFED63+fa/wYW3qoJWfMCtxwjQgXFywEml+dVgU8L
9fVQRLf39d1bvXCGYovofEHRBeVxZkBQ1Jo0JHoGDOwNCNdyBQjXBYd1HFUtEOmE
vp540GsoXsXXNC4j/rFfhY87zJ8wI6PvBOEztu9rk0+cM0JPkIADpSgLT1njQWa9
FoTqlYdktp2y2Q0aZXY6lnUhSsJDDkLRtaySwULfXyYsKz6H4PRe4gZe3TFuJMgw
mNpnVSP8bxbD2JNugm4AiontICnauMJR6NW/H0qCxyD8oJzvEcpt1umO6dUF+ESb
5+5FJe+ngBThJ4RX4R7371So8lKCuHyHQ5L4QiAFq060V8af8HpDdTTj6vxiKxVc
Co/sHT8vbk4zc1bADsOKqUcvWxJbtav7cyl8nY5ejTIXQYF5RKhk8Qmh/lJ9U8yF
v8vRDvpnc4eE1/1Z765uXDOajELip/dKFMBU2iVvW7JuXjsLyLH7hMeDHSjBvynA
m/GEGitI0gZk/OddhQXv/BrljgpGHJQTJosmK8q2xDfSRHEk2pXzTwbXokhuNKYd
JXLM4RgJW0dyQpDxGHK/EUPekDWyGX7c3lCenbXrtckSgKW566c=
=IfD6
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to