You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by chrisneal <ch...@pegs.com> on 2008/05/23 16:32:29 UTC

Is there a way to force namespace prefixes to appear?

Hello all,

I've got a XML document build that looks like this:

		<MessageHeader
xmlns="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd"
soapenv:mustUnderstand="0">
			<From>
				<PartyId>myparth</PartyId>
			</From>
			<To>
				<PartyId>theirparty</PartyId>
			</To>
			<CPAId>somethinghere</CPAId>
			<ConversationId>blah</ConversationId>
			<Service
xmlns:axis2ns2="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd"
axis2ns2:type="4.0">data</Service>
			<Action>data</Action>
			<MessageData>
				<MessageId>1</MessageId>
				<Timestamp>2008-05-22T15:33:02.576-05:00</Timestamp>
			</MessageData>
		</MessageHeader>

which is completely valid.  But for some reason, if I don't make it look
like this:

    <ns2:MessageHeader xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns2="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd"
ns1:mustUnderstand="false" ns2:version="4.0">
      <ns2:From>
        <ns2:PartyId>data</ns2:PartyId>
      </ns2:From>
      <ns2:To>
        <ns2:PartyId>data</ns2:PartyId>
      </ns2:To>
      <ns2:CPAId>data</ns2:CPAId>
      <ns2:ConversationId>data</ns2:ConversationId>
      <ns2:Service ns2:type="4.0">data</ns2:Service>
      <ns2:Action>data</ns2:Action>
      <ns2:MessageData>
        <ns2:MessageId>30094</ns2:MessageId>
        <ns2:Timestamp>2007-08-14T15:41:21.466-05:00</ns2:Timestamp>
      </ns2:MessageData>
    </ns2:MessageHeader>

Then the service errors out with a bunch of "Unexpected element" messages.
:S

Is there a way in xmlbeans to have it redundantly display the namespace
prefix?

Thanks!

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


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


Re: Is there a way to force namespace prefixes to appear?

Posted by chrisneal <ch...@pegs.com>.
Ok, I'm still trying to work through this, and things just get more and more
weird.

I tried a difference approach this time.  Take a known working MessageHeader
element as a String, and build up the the object like this instead:

 MessageHeaderDocument ebDoc = MessageHeaderDocument.Factory.parse(
      "<ns2:MessageHeader
xmlns:ns1=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:ns2=\"http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd\"
ns1:mustUnderstand=\"false\" ns2:version=\"4.0\">      <ns2:From>       
<ns2:PartyId>data</ns2:PartyId>      </ns2:From>      <ns2:To>       
<ns2:PartyId>data</ns2:PartyId>      </ns2:To>     
<ns2:CPAId>data</ns2:CPAId>     
<ns2:ConversationId>data</ns2:ConversationId>      <ns2:Service
ns2:type=\"4.0\">data</ns2:Service>      <ns2:Action>data</ns2:Action>     
<ns2:MessageData>        <ns2:MessageId>30094</ns2:MessageId>       
<ns2:Timestamp>2007-08-14T15:41:21.466-05:00</ns2:Timestamp>     
</ns2:MessageData>    </ns2:MessageHeader>");

So far, so good.  

Then I print out the XML doc with both the xmlText() and toString() methods,
which both match what I created with the parse() method's input.

ebDoc.toString():
<ns2:MessageHeader ns1:mustUnderstand="false" ns2:version="4.0"
xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns2="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd">
  <ns2:From>
    <ns2:PartyId>data</ns2:PartyId>
  </ns2:From>
  <ns2:To>
    <ns2:PartyId>data</ns2:PartyId>
  </ns2:To>
  <ns2:CPAId>data</ns2:CPAId>
  <ns2:ConversationId>data</ns2:ConversationId>
  <ns2:Service ns2:type="4.0">data</ns2:Service>
  <ns2:Action>data</ns2:Action>
  <ns2:MessageData>
    <ns2:MessageId>30094</ns2:MessageId>
    <ns2:Timestamp>2007-08-14T15:41:21.466-05:00</ns2:Timestamp>
  </ns2:MessageData>
</ns2:MessageHeader>

Still so far so good.  But then, somewhere, down in the guts of xmlbeans,
for some reason, the data in the XML document gets changed, and I don't know
why.  I traced the HTTP stream that gets sent to the web service with
Ethereal so I could see what actually get's sent, and *this* MessageHeader
is different?!  Here is what actually gets sent:

		<ns2:MessageHeader
xmlns:ns2="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd"
soapenv:mustUnderstand="0">
			<ns2:From>
				<ns2:PartyId>data</ns2:PartyId>
			</ns2:From>
			<ns2:To>
				<ns2:PartyId>data</ns2:PartyId>
			</ns2:To>
			<ns2:CPAId>data</ns2:CPAId>
			<ns2:ConversationId>data</ns2:ConversationId>
			<ns2:Service ns2:type="4.0">data</ns2:Service>
			<ns2:Action>data</ns2:Action>
			<ns2:MessageData>
				<ns2:MessageId>30094</ns2:MessageId>
				<ns2:Timestamp>2007-08-14T15:41:21.466-05:00</ns2:Timestamp>
			</ns2:MessageData>
		</ns2:MessageHeader>

Notice that the "version" attribute in the MessageHeader is now gone, as is
the ns1 namespace prefix definition.  Apparently those are both critical
components, because the error from the JAXB parser on the web service side
is still:

Unexpected element
http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd}:From
Unexpected element
{http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd}:To
Unexpected element
http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd}:CPAId
Unexpected element
{http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd}:ConversationId
Unexpected element
{http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd}:Service
Unexpected element
{http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd}:Action
Unexpected element
{http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd}:MessageData
Unexpected end of element
{http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd}:MessageHeader

Sorry to beat this one to death with reposts, but it's the last issue I have
before I can say I have a working client.  :S  Any help or thoughts or ideas
would be really appreciated.

Thanks so much,
chris


chrisneal wrote:
> 
> Hello all,
> 
> I've got a XML document build that looks like this:
> 
> 		<MessageHeader
> xmlns="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd"
> soapenv:mustUnderstand="0">
> 			<From>
> 				<PartyId>myparth</PartyId>
> 			</From>
> 			<To>
> 				<PartyId>theirparty</PartyId>
> 			</To>
> 			<CPAId>somethinghere</CPAId>
> 			<ConversationId>blah</ConversationId>
> 			<Service
> xmlns:axis2ns2="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd"
> axis2ns2:type="4.0">data</Service>
> 			<Action>data</Action>
> 			<MessageData>
> 				<MessageId>1</MessageId>
> 				<Timestamp>2008-05-22T15:33:02.576-05:00</Timestamp>
> 			</MessageData>
> 		</MessageHeader>
> 
> which is completely valid.  But for some reason, if I don't make it look
> like this:
> 
>     <ns2:MessageHeader
> xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:ns2="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd"
> ns1:mustUnderstand="false" ns2:version="4.0">
>       <ns2:From>
>         <ns2:PartyId>data</ns2:PartyId>
>       </ns2:From>
>       <ns2:To>
>         <ns2:PartyId>data</ns2:PartyId>
>       </ns2:To>
>       <ns2:CPAId>data</ns2:CPAId>
>       <ns2:ConversationId>data</ns2:ConversationId>
>       <ns2:Service ns2:type="4.0">data</ns2:Service>
>       <ns2:Action>data</ns2:Action>
>       <ns2:MessageData>
>         <ns2:MessageId>30094</ns2:MessageId>
>         <ns2:Timestamp>2007-08-14T15:41:21.466-05:00</ns2:Timestamp>
>       </ns2:MessageData>
>     </ns2:MessageHeader>
> 
> Then the service errors out with a bunch of "Unexpected element" messages.
> :S
> 
> Is there a way in xmlbeans to have it redundantly display the namespace
> prefix?
> 
> Thanks!
> 
> 

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


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


Re: Is there a way to force namespace prefixes to appear?

Posted by chrisneal <ch...@pegs.com>.
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: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: Is there a way to force namespace prefixes to appear?

Posted by J B <mo...@gmail.com>.
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

On Fri, May 23, 2008 at 11:26 AM, Jacob Danner <ja...@gmail.com> wrote:
> Hi,
> Have you tried validating the content? I'm curious what the output is.
> I would be extremely surprised if the/a namespace prefix were
> required. When I've seen this error when dealing with web services, it
> usually indicates an element is out of order.
> -jacobd
>
> On Fri, May 23, 2008 at 7:32 AM, chrisneal <ch...@pegs.com> wrote:
>>
>> Hello all,
>>
>> I've got a XML document build that looks like this:
>>
>>                <MessageHeader
>> xmlns="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd"
>> soapenv:mustUnderstand="0">
>>                        <From>
>>                                <PartyId>myparth</PartyId>
>>                        </From>
>>                        <To>
>>                                <PartyId>theirparty</PartyId>
>>                        </To>
>>                        <CPAId>somethinghere</CPAId>
>>                        <ConversationId>blah</ConversationId>
>>                        <Service
>> xmlns:axis2ns2="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd"
>> axis2ns2:type="4.0">data</Service>
>>                        <Action>data</Action>
>>                        <MessageData>
>>                                <MessageId>1</MessageId>
>>                                <Timestamp>2008-05-22T15:33:02.576-05:00</Timestamp>
>>                        </MessageData>
>>                </MessageHeader>
>>
>> which is completely valid.  But for some reason, if I don't make it look
>> like this:
>>
>>    <ns2:MessageHeader xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/"
>> xmlns:ns2="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd"
>> ns1:mustUnderstand="false" ns2:version="4.0">
>>      <ns2:From>
>>        <ns2:PartyId>data</ns2:PartyId>
>>      </ns2:From>
>>      <ns2:To>
>>        <ns2:PartyId>data</ns2:PartyId>
>>      </ns2:To>
>>      <ns2:CPAId>data</ns2:CPAId>
>>      <ns2:ConversationId>data</ns2:ConversationId>
>>      <ns2:Service ns2:type="4.0">data</ns2:Service>
>>      <ns2:Action>data</ns2:Action>
>>      <ns2:MessageData>
>>        <ns2:MessageId>30094</ns2:MessageId>
>>        <ns2:Timestamp>2007-08-14T15:41:21.466-05:00</ns2:Timestamp>
>>      </ns2:MessageData>
>>    </ns2:MessageHeader>
>>
>> Then the service errors out with a bunch of "Unexpected element" messages.
>> :S
>>
>> Is there a way in xmlbeans to have it redundantly display the namespace
>> prefix?
>>
>> Thanks!
>>
>> --
>> View this message in context: http://www.nabble.com/Is-there-a-way-to-force-namespace-prefixes-to-appear--tp17426936p17426936.html
>> Sent from the Xml Beans - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>> For additional commands, e-mail: user-help@xmlbeans.apache.org
>>
>>
>
>
>
> --
> I'm competing in a Half-Ironman distance triathlon to raise money for
> the fight against cancer!
> Please help support my efforts by going to:
> http://www.active.com/donate/tntwaak/jacobd
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
>
>

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


Re: Is there a way to force namespace prefixes to appear?

Posted by Jacob Danner <ja...@gmail.com>.
Hi,
Have you tried validating the content? I'm curious what the output is.
I would be extremely surprised if the/a namespace prefix were
required. When I've seen this error when dealing with web services, it
usually indicates an element is out of order.
-jacobd

On Fri, May 23, 2008 at 7:32 AM, chrisneal <ch...@pegs.com> wrote:
>
> Hello all,
>
> I've got a XML document build that looks like this:
>
>                <MessageHeader
> xmlns="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd"
> soapenv:mustUnderstand="0">
>                        <From>
>                                <PartyId>myparth</PartyId>
>                        </From>
>                        <To>
>                                <PartyId>theirparty</PartyId>
>                        </To>
>                        <CPAId>somethinghere</CPAId>
>                        <ConversationId>blah</ConversationId>
>                        <Service
> xmlns:axis2ns2="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd"
> axis2ns2:type="4.0">data</Service>
>                        <Action>data</Action>
>                        <MessageData>
>                                <MessageId>1</MessageId>
>                                <Timestamp>2008-05-22T15:33:02.576-05:00</Timestamp>
>                        </MessageData>
>                </MessageHeader>
>
> which is completely valid.  But for some reason, if I don't make it look
> like this:
>
>    <ns2:MessageHeader xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:ns2="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd"
> ns1:mustUnderstand="false" ns2:version="4.0">
>      <ns2:From>
>        <ns2:PartyId>data</ns2:PartyId>
>      </ns2:From>
>      <ns2:To>
>        <ns2:PartyId>data</ns2:PartyId>
>      </ns2:To>
>      <ns2:CPAId>data</ns2:CPAId>
>      <ns2:ConversationId>data</ns2:ConversationId>
>      <ns2:Service ns2:type="4.0">data</ns2:Service>
>      <ns2:Action>data</ns2:Action>
>      <ns2:MessageData>
>        <ns2:MessageId>30094</ns2:MessageId>
>        <ns2:Timestamp>2007-08-14T15:41:21.466-05:00</ns2:Timestamp>
>      </ns2:MessageData>
>    </ns2:MessageHeader>
>
> Then the service errors out with a bunch of "Unexpected element" messages.
> :S
>
> Is there a way in xmlbeans to have it redundantly display the namespace
> prefix?
>
> Thanks!
>
> --
> View this message in context: http://www.nabble.com/Is-there-a-way-to-force-namespace-prefixes-to-appear--tp17426936p17426936.html
> Sent from the Xml Beans - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
>
>



-- 
I'm competing in a Half-Ironman distance triathlon to raise money for
the fight against cancer!
Please help support my efforts by going to:
http://www.active.com/donate/tntwaak/jacobd

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