You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by re...@it-xpert.be on 2007/01/24 12:46:41 UTC

namespace problem

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

Re: namespace problem

Posted by Bruno Delzant <re...@it-xpert.be>.
It's indeed strange. Don't look at element values like Doc:MsgId. Those 
values are put by a plugin I have that generates xml from xsd.
The value itself has nothing to do with my namespace problem.

Anyone has an hint on this issue ?

Bruno

----- Original Message ----- 
From: "Cezar Andrei" <ce...@bea.com>
To: <us...@xmlbeans.apache.org>
Sent: Wednesday, January 24, 2007 5:38 PM
Subject: RE: namespace problem


Assuming that all your schema that you used to generate these Xbeans
from is in "urn:xsd:$pacs.002.002.02" namespace, it is strange that this
happens. But there is <MsgId>Doc:MsgId</MsgId> in both messages, which
looks like a QName. Maybe the schema you're using isn't free of
namespace "xml.staqs.nba.com".

Cezar



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


RE: namespace problem

Posted by Cezar Andrei <ce...@bea.com>.
Assuming that all your schema that you used to generate these Xbeans
from is in "urn:xsd:$pacs.002.002.02" namespace, it is strange that this
happens. But there is <MsgId>Doc:MsgId</MsgId> in both messages, which
looks like a QName. Maybe the schema you're using isn't free of
namespace "xml.staqs.nba.com".

Cezar


> -----Original Message-----
> From: register@it-xpert.be [mailto:register@it-xpert.be]
> Sent: Wednesday, January 24, 2007 5:47 AM
> To: user@xmlbeans.apache.org
> Subject: namespace problem
> 
> 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().getInstdA
gt
> ().getFinInstnId().getBIC());
> 
> and line (2) by:
> 
>
hdr.addNewInstgAgt().addNewFinInstnId().setBIC(msg.getGrpHdr().getInstgA
gt
> ().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
_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org