Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VTD-XML shadows namespace from sibling element and add unexpected ns #13

Open
ronindev opened this issue Sep 23, 2019 · 0 comments
Open

Comments

@ronindev
Copy link

I have an issue when trying to extract element via getElementFragmentNs.

Here sample test:

 @Test
    public void shouldNotShadowNamespaceAndAddSiblingNamespaces() throws Exception {
        byte[] bytes = ("<ns2:Response xmlns=\"urn://message\" xmlns:ns2=\"urn://ns2\">\n" +
                "    <ns2:Data Id=\"SIGNED_BY_CONSUMER\">\n" +
                "        <Content>\n" +
                "            <tns:Response\n" +
                "                    xmlns:tns=\"urn://tns\"\n" +
                "                    xmlns=\"urn://shadow\">\n" +
                "                <tns:test/>\n" +
                "            </tns:Response>\n" +
                "        </Content>\n" +
                "        <AttachmentHeaderList>\n" +
                "            <AttachmentHeader/>\n" +
                "        </AttachmentHeaderList>\n" +
                "    </ns2:Data>\n" +
                "</ns2:Response>").getBytes("UTF-8");

        VTDGen vg = new VTDGen();
        vg.setDoc(bytes);
        vg.parse(true);  // set namespace awareness to true

        VTDNav vn = vg.getNav();
        AutoPilot ap = new AutoPilot(vn);
        ap.selectElement("AttachmentHeader");
        ap.iterate();

        ElementFragmentNs efn = vn.getElementFragmentNs();
        byte[] result = efn.toBytes();
        assertThat(new String(result, "UTF-8"), is("<AttachmentHeader xmlns=\"urn://message/\"/>"));
    }

The actual result is:

<AttachmentHeader xmlns:tns="urn://tns" xmlns="urn://shadow" xmlns:ns2="urn://ns2"/>

But I expect:

<AttachmentHeader xmlns="urn://message/"/>

Why it shadows default namespace with default namespace from sibling subelement? And why it adds unnecessary namespaces from it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant