Hi,

I am working with some xml def standards that are not so well
defined (life is hard sometimes). So to be able to accept
several messages coming in different namespaces (they should
be in the name ideally for the process I have to do, like
automatic comparison to each other), I use the
XmlOptions.setLoadSubstituteNamespaces method to put them all
in a common namespaces.
It works very well.

In my processing I generate some output messages. Those messages
are defined in my common namespace, but I have to substitute
them to another namepace (to respect those damn standards).
I have seen on some threads already a suggestion of parsing with
an XmlCursor the xml tree and setting new Qname (keeping the
local part but changing the prefix).
It works very well, but for some reason I do not understand I
get additional namespace declaration inside the xml.

Here is an example:
<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:xsd:$pacs.002.002.02">
    <pacs.002.002.02>
        <GrpHdr>
            <MsgId>Doc:MsgId</MsgId>
            <CreDtTm>2001-12-31T12:00:00</CreDtTm>
            <InstgAgt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:Doc="xml.staqs.nba.com">
                <FinInstnId>
                    <BIC>BNPAFRPPAFI</BIC>
                </FinInstnId>
            </InstgAgt>
            <InstdAgt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:Doc="xml.staqs.nba.com">
                <FinInstnId>
                    <BIC>BNPAFRPPAFI</BIC>
                </FinInstnId>
            </InstdAgt>
        </GrpHdr>
    </pacs.002.002.02>
</Document>

For element InstgAgt and InstdAgt I have a unused namespace declaration.
How to avoid this ?

Note that is generated when I copy some part of xml tree from a source xml
to a target xml, like this:

  public static Pacs00200202 generateGenericHeader(Pacs00300202 msg) {
    Pacs00200202 doc = Pacs00200202.Factory.newInstance();

    GroupHeader12 hdr = doc.addNewGrpHdr();
    hdr.setMsgId(msg.getGrpHdr().getMsgId());
    hdr.setCreDtTm(msg.getGrpHdr().getCreDtTm());

(1) hdr.setInstdAgt(msg.getGrpHdr().getInstdAgt());
(2) hdr.setInstgAgt(msg.getGrpHdr().getInstgAgt());

    return doc;
  }

If I replace line (1) by:
 
hdr.addNewInstdAgt().addNewFinInstnId().setBIC(msg.getGrpHdr().getInstdAgt().getFinInstnId().getBIC());

and line (2) by:
 
hdr.addNewInstgAgt().addNewFinInstnId().setBIC(msg.getGrpHdr().getInstgAgt().getFinInstnId().getBIC());

I get a correct XML:
<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:xsd:$pacs.002.002.02">
    <pacs.002.002.02>
        <GrpHdr>
            <MsgId>Doc:MsgId</MsgId>
            <CreDtTm>2001-12-31T12:00:00</CreDtTm>
            <InstgAgt>
                <FinInstnId>
                    <BIC>BNPAFRPPAFI</BIC>
                </FinInstnId>
            </InstgAgt>
            <InstdAgt>
                <FinInstnId>
                    <BIC>BNPAFRPPAFI</BIC>
                </FinInstnId>
            </InstdAgt>
        </GrpHdr>
    </pacs.002.002.02>
</Document>

Why this different behaviour in this two cases ?

Thanks,
Bruno

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Attachment: file
Description: boundary/----

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to