Thanks Birch!

I added that code (I had actually tried something very similar with no luck)
and the output generated by xmlText() still has all the namespace prefixes,
AS DOES the ouput generated by the xmlObject.save(System.out, xmlOptions),
BUT the message actually sent on the wire to the web service still does not
have them.  I traced the line with Ethereal to make sure.  I'm stumped.

Here's my method, and it's output.  Any other ideas?!  This seems very
strange.

CODE:
--------------------------------
  private static MessageHeaderDocument buildMessageHeader() {
    
    MessageHeaderDocument ebDoc =
MessageHeaderDocument.Factory.newInstance();  
    MessageHeaderDocument.MessageHeader msgHeader =
ebDoc.addNewMessageHeader();
    
    msgHeader.setMustUnderstand(false);
    msgHeader.setVersion("4.0");
    msgHeader.setCPAId("data");
    msgHeader.setConversationId("data");
    
    FromDocument.From from = msgHeader.addNewFrom();
    PartyIdDocument.PartyId partyId1 = from.addNewPartyId();
    partyId1.setStringValue("data");
    
    ToDocument.To to = msgHeader.addNewTo();
    PartyIdDocument.PartyId partyId = to.addNewPartyId();
    partyId.setStringValue("data");
    
    ServiceDocument.Service service = msgHeader.addNewService();
    service.setStringValue("data");
    service.setType("4.0");
    
    msgHeader.setAction("data");
    
    MessageDataDocument.MessageData messageData =
msgHeader.addNewMessageData();
    messageData.setMessageId("1");
    messageData.setTimestamp(Calendar.getInstance());
    
    XmlOptions xmlOptions = new XmlOptions();
    java.util.Map namespaceMap = new java.util.HashMap();
   
namespaceMap.put("http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd";,
"eb");
    xmlOptions.setSaveSuggestedPrefixes(namespaceMap);
    try {
      System.out.println("\n\nSAVING...\n\n");
      ebDoc.save(System.out, xmlOptions);
    } catch (java.io.IOException i) {
      
    }    
    System.out.println("\nebDoc.xmlText():\n"+ebDoc.xmlText());
    System.out.println("\nebDoc.toString():\n"+ebDoc.toString());    
    
    return ebDoc;
  }

OUTPUT HERE:
---------------------------------------
SAVING...


<?xml version="1.0" encoding="UTF-8"?>
<eb:MessageHeader soapenv:mustUnderstand="false" eb:version="4.0"
xmlns:eb="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd";
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/";><eb:From><eb:PartyId>data</eb:PartyId></eb:From><eb:To><eb:PartyId>data</eb:PartyId></eb:To><eb:CPAId>data</eb:CPAId><eb:ConversationId>data</eb:ConversationId><eb:Service
eb:type="4.0">data</eb:Service><eb:Action>data</eb:Action><eb:MessageData><eb:MessageId>1</eb:MessageId><eb:Timestamp>2008-05-29T16:01:02.026-05:00</eb:Timestamp></eb:MessageData></eb:MessageHeader>

ebDoc.xmlText():
<msg:MessageHeader soapenv:mustUnderstand="false" msg:version="4.0"
xmlns:msg="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd";
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/";><msg:From><msg:PartyId>data</msg:PartyId></msg:From><msg:To><msg:PartyId>data</msg:PartyId></msg:To><msg:CPAId>data</msg:CPAId><msg:ConversationId>data</msg:ConversationId><msg:Service
msg:type="4.0">data</msg:Service><msg:Action>data</msg:Action><msg:MessageData><msg:MessageId>1</msg:MessageId><msg:Timestamp>2008-05-29T16:01:02.026-05:00</msg:Timestamp></msg:MessageData></msg:MessageHeader>

ebDoc.toString():
<MessageHeader soapenv:mustUnderstand="false" msg:version="4.0"
xmlns="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd";
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/";
xmlns:msg="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd";>
  <From>
    <PartyId>data</PartyId>
  </From>
  <To>
    <PartyId>data</PartyId>
  </To>
  <CPAId>data</CPAId>
  <ConversationId>data</ConversationId>
  <Service msg:type="4.0">data</Service>
  <Action>data</Action>
  <MessageData>
    <MessageId>1</MessageId>
    <Timestamp>2008-05-29T16:01:02.026-05:00</Timestamp>
  </MessageData>
</MessageHeader>

Sorry for the ugly paste :S
chris


moatas wrote:
> 
> XmlOptions xmlOptions = new XmlOptions();
> 
> //key = uri, value = prefix
> Map<String, String> namespaceMap = new HashMap<String, String>();
> namespaceMap.put("http://foo.com/bar";, "foo");
> xmlOptons.setSaveSuggestedPrefixes(namespaceMap);
> 
> xmlObject.save(System.out, xmlOptions);
> 
> The above should force the namespace of http://foo.com/bar to be
> prefixed with foo:
> 
> Birch
> 

-- 
View this message in context: 
http://www.nabble.com/Is-there-a-way-to-force-namespace-prefixes-to-appear--tp17426936p17545881.html
Sent from the Xml Beans - User mailing list archive at Nabble.com.


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

Reply via email to