Author |
Message
|
dweller |
Posted: Tue Dec 19, 2006 7:09 am Post subject: xml declaration issues |
|
|
Apprentice
Joined: 31 Oct 2006 Posts: 28
|
Hi,
i'm trying to add xml declaration to a message.
this ESQL (found this in wmb tookit's help)
SET OutputRoot.XMLNSC.(XMLNSC.XmlDeclaration)*.Version = 1.0;
SET OutputRoot.XMLNSC.(XMLNSC.XmlDeclaration)*.Encoding = 'UTF8';
produces me following results:
XmlDeclaration, as element name, is missing.
What am i doing wrong?
wmb 6.0.0.3 |
|
Back to top |
|
 |
special_agent_Queue |
Posted: Tue Dec 19, 2006 7:23 am Post subject: |
|
|
 Centurion
Joined: 27 Jul 2006 Posts: 102
|
That code is incorrect.
Use the following:
Code: |
SET OutputRoot.XMLNSC.(XMLNSC.XmlDeclaration) = '';
SET OutputRoot.XMLNSC.(XMLNSC.XmlDeclaration).(XMLNSC.Attribute)version = '1.0';
SET OutputRoot.XMLNSC.(XMLNSC.XmlDeclaration).(XMLNSC.Attribute)encoding = 'UTF-8'; |
Also from the wmb toolkit help:
Quote: |
In the XMLNSC domain there is no special type for the XML version; it is simply treated as an attribute of the XML declaration. The equivalent syntax for the above example is:
SET OutputRoot.XMLNSC.(XMLNSC.XmlDeclaration)*.(XMLNSC.Attribute)Version = '1.0';
In a similar way in the XMLNSC domain the XML encoding type and XML standalone mode are also processed simply as attributes of the XML declaration and can be set up in ESQL as follows:
SET OutputRoot.XMLNSC.(XMLNSC.XmlDeclaration)*.(XMLNSC.Attribute)Encoding = 'UTF-8';
|
|
|
Back to top |
|
 |
kimbert |
Posted: Tue Dec 19, 2006 7:27 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
XmlDeclaration, as element name, is missing |
That does not matter. You should find that the message gets serialized correctly anyway. It is the correlation name ( XMLNSC.Declaration ) which really matters.
If you really care, give it a name - the XMLNSC parser won't mind:
Code: |
SET OutputRoot.XMLNSC.(XMLNSC.XmlDeclaration)XmlDeclaration.(XMLNSC.Attribute)version = '1.0';
SET OutputRoot.XMLNSC.(XMLNSC.XmlDeclaration)XmlDeclaration.(XMLNSC.Attribute)encoding = 'UTF-8'; |
|
|
Back to top |
|
 |
dweller |
Posted: Tue Dec 19, 2006 7:39 am Post subject: |
|
|
Apprentice
Joined: 31 Oct 2006 Posts: 28
|
thanx both,
special_agent_Queue's code shows same result in debug, so i guess both ways are correct.
so i think problem is here, because i have to put whole message in the envelope:
SET OutputRoot.XMLNSC.Envelope.Data = InputRoot.XMLNSC;
after going through mqoutput and mqinput, that blank element dissapears.
any suggestions here? |
|
Back to top |
|
 |
special_agent_Queue |
Posted: Tue Dec 19, 2006 7:44 am Post subject: |
|
|
 Centurion
Joined: 27 Jul 2006 Posts: 102
|
dweller wrote: |
after going through mqoutput and mqinput, that blank element dissapears.
any suggestions here? |
Not sure what you mean. Are you saying that it results in
<?xml version="1.0" encoding="UTF-8"?> ?
If so, that is what it should do... and is the result of an xml declaration statement. |
|
Back to top |
|
 |
dweller |
Posted: Tue Dec 19, 2006 7:52 am Post subject: |
|
|
Apprentice
Joined: 31 Oct 2006 Posts: 28
|
if before mqoutput node my message is in OutputRoot.XMLNSC, then it gets xml declaration.
but i have to put whole message in envelope (OutputRoot.XMLNSC.Envelope.Data)
in this case xml declaration dissapears. |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Dec 19, 2006 7:56 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
You can't have more than one XML declaration in one document.
You probably don't want the XML declaration for the original message in the message anyway.
Also, you should be using OutputRoot.XMLNSC.Envelope.Body, not Data - if you are doing Soap messaging.
You should use the previous code here to create your XML declaration at the root level, and then put your data into OutputRoot.XMLNSC.Envelope.whatever. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
special_agent_Queue |
Posted: Tue Dec 19, 2006 7:57 am Post subject: |
|
|
 Centurion
Joined: 27 Jul 2006 Posts: 102
|
You can do this by saying:
Code: |
SET OutputRoot.XMLNSC.Envelope.Data.(XMLNSC.XmlDeclaration) = '';
SET OutputRoot.XMLNSC.Envelope.Data.(XMLNSC.XmlDeclaration).(XMLNSC.Attribute)version = '1.0';
SET OutputRoot.XMLNSC.Envelope.Data.(XMLNSC.XmlDeclaration).(XMLNSC.Attribute)encoding = 'UTF-8';
SET OutputRoot.XMLNSC.Envelope.Data = InputRoot.XMLNSC; |
|
|
Back to top |
|
 |
gregop |
Posted: Tue Dec 19, 2006 7:57 am Post subject: |
|
|
Voyager
Joined: 24 Nov 2006 Posts: 81
|
This is probably due to XMLNSC discarding document declaration by default.
Documenatation says:
Quote: |
XMLNSC parser modes
By default, the XMLNSC parser discards document elements that typically carry no business meaning. However, parser modes are available to force retention of these elements. You can configure these modes on the properties of the node that specifies the message is to be parsed in the XMLNSC domain.
The valid parser modes for the XMLNSC parser are:
XMLNSC.MixedContentRetainNone
XMLNSC.MixedContentRetainAll
XMLNSC.CommentsRetainNone
XMLNSC.CommentsRetainAll
XMLNSC.ProcessingInstructionsRetainNone
XMLNSC.ProcessingInstructionsRetainAll
The following example uses the XMLNSC.ProcessingInstructionsRetainAll and XMLNSC.ProcessingInstructionsRetainNone modes to retain document processing instructions while parsing:
DECLARE X BLOB ASBITSTREAM(InputRoot.XMLNSC.Data OPTIONS XMLNSC
.ProcessingInstructionsRetainAll);
...
CREATE LASTCHILD OF outputRoot PARSE(X OPTIONS XMLNSC
.ProcessingInstructionsRetainNone);
|
|
|
Back to top |
|
 |
dweller |
Posted: Tue Dec 19, 2006 8:02 am Post subject: |
|
|
Apprentice
Joined: 31 Oct 2006 Posts: 28
|
thanx everybody, now i see my mistake, so i will do it the right way when necessary.
for now i solved my problem by creating xml declaration in my other flow, which extracts message from envelope  |
|
Back to top |
|
 |
special_agent_Queue |
Posted: Tue Dec 19, 2006 8:02 am Post subject: |
|
|
 Centurion
Joined: 27 Jul 2006 Posts: 102
|
jefflowrey wrote: |
You can't have more than one XML declaration in one document. |
Just wondering if this is stated somewhere. I'm using multiple XML declarations in a soap/mime message and it hasn't been a problem.
jefflowrey wrote: |
You probably don't want the XML declaration for the original message in the message anyway. |
Why not? |
|
Back to top |
|
 |
kimbert |
Posted: Tue Dec 19, 2006 8:02 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
dweller : Your code ( and my copy of it ) uses 'version' and 'encoding' but the docs say 'Version' and 'Encoding'. The docs are correct.
Jeff is correct to point out that the XML declaration must be a child of XMLNSC. ( so don't use the code which special_agent_Queue posted )
gregop : Not quite correct. XMLNSC never puts an inline DTD ( DOCTYPE ) into the message tree. It does put the XML declaration into the message tree. |
|
Back to top |
|
 |
4integration |
Posted: Wed Jun 27, 2007 11:58 am Post subject: |
|
|
 Disciple
Joined: 04 Sep 2006 Posts: 197 Location: Gothenburg, Sweden
|
special_agent_Queue wrote: |
Use the following:
Code: |
SET OutputRoot.XMLNSC.(XMLNSC.XmlDeclaration) = '';
SET OutputRoot.XMLNSC.(XMLNSC.XmlDeclaration).(XMLNSC.Attribute)version = '1.0';
SET OutputRoot.XMLNSC.(XMLNSC.XmlDeclaration).(XMLNSC.Attribute)encoding = 'UTF-8'; |
|
I have tried to set encoding (I already have the XMLNSC/XmlDeclaration/Version) with JCN/xPath and the following code...
Code: |
MbElement root = outAssembly.getMbMessage().getRootElement();
MbXPath xp = new MbXPath("/XMLNSC/?XmlDeclaration/?@Encoding[set-value('UTF-8')]", root);
root.evaluateXPath(xp); |
But this creates a new XMLNSC/XmlDeclaration with Encoding, not creating the attribute in the existing XmlDeclaration. What am I missing? _________________ Best regards
4 Integration |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Jun 27, 2007 12:14 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
You might be missing that "encoding" is different than "Encoding".
But you're probably missing that XmlDeclaration is of a special type, and is likely not an element - which your XPath implies that it should be. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
kimbert |
Posted: Wed Jun 27, 2007 3:12 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
This should work...it's in the latest version of the docs:
Quote: |
//Create the XML domain root node
MBElement xmlRoot = root.createElementAsLastChild(MbXMLNS.PARSER_NAME);
//Create the XML declaration parent node
MbElement xmlDecl = xmlRoot.createElementAsFirstChild(MbXMLNSC.XML_DECLARATION);
xmlDecl.setName("XmlDeclaration");
MbElement version = xmlDecl.CreateElementAsFirstChild(MbXMLNSC.ATTRIBUTE, "Version", "1.0");
MbElement encoding = xmlDecl.CreateElementAsFirstChild(MbXMLNSC.ATTRIBUTE, "Encoding", "utf-8");
|
|
|
Back to top |
|
 |
|