J. Nicholas
J. Nicholas

Reputation: 105

SaxonJS emits superfulous namespace attributes

When using SaxonJS, I am able to verify that it produces the same output as Saxon, with one caveat. It appears that SaxonJS will emit namespace attributes for every element, even when they are not needed. I tried adjusting exclude-result-prefixes, but this had no effect.

SaxonJS 1.2.0 Output

<CastVoteRecordReport xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="NIST_V0_cast_vote_records.xsd" xsi:schemaLocation="NIST_V0_cast_vote_records.xsd NIST_V0_cast_vote_records.xsd">
    <CVR xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="NIST_V0_cast_vote_records.xsd">
        <BallotStyleId xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="NIST_V0_cast_vote_records.xsd">_01-0052-01</BallotStyleId>
        <CreatingDeviceId xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="NIST_V0_cast_vote_records.xsd">rd</CreatingDeviceId>
        <CurrentSnapshotId xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="NIST_V0_cast_vote_records.xsd">i__a_aaaaaago</CurrentSnapshotId>
        <CVRSnapshot xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="NIST_V0_cast_vote_records.xsd" ObjectId="i__a_aaaaaago">
            <CVRContest xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="NIST_V0_cast_vote_records.xsd">
                <ContestId xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="NIST_V0_cast_vote_records.xsd">_1GO</ContestId>
                <Undervotes xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="NIST_V0_cast_vote_records.xsd">1</Undervotes>
            </CVRContest>
...

Saxon-EE version 9.8.0.12 output

<?xml version="1.0" encoding="UTF-8"?>
<CastVoteRecordReport xmlns="NIST_V0_cast_vote_records.xsd"
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <CVR>
      <BallotStyleId>_01-0052-01</BallotStyleId>
      <CreatingDeviceId>rd</CreatingDeviceId>
      <CurrentSnapshotId>i__a_aaaaaago</CurrentSnapshotId>
      <CVRSnapshot ObjectId="i__a_aaaaaago">
         <CVRContest>
            <ContestId>_1GO</ContestId>
            <Undervotes>1</Undervotes>
         </CVRContest>
...

The callback on SaxonJS.Transform is

var transformCallback = (fragment: DocumentFragment) => {
            // have to convert to string?
            var div = document.createElement('div');
            div.appendChild(fragment.cloneNode(true));
            // replace existing output content
            that.outputText(div.innerHTML);
}

Upvotes: 0

Views: 134

Answers (1)

Michael Kay
Michael Kay

Reputation: 163262

Saxon-JS 1.2.0 does not have a (complete, conformant) serializer, so the question arises, how are you producing the lexical XML output shown in your question?

In terms of the XDM data model, the XML and XSI namespaces should indeed be in scope on every element in the result tree; a good serializer will eliminate namespaces that are redundant. So this is all a question about how the result tree is being serialized.

(Note, Saxon-JS 2.0, which is the final stages of testing, will have a full serializer.)

Upvotes: 1

Related Questions