Author |
Message
|
elwis |
Posted: Tue Jun 30, 2009 2:53 am Post subject: Xmldeclaration in ESQL |
|
|
Apprentice
Joined: 02 Apr 2008 Posts: 26 Location: Sweden
|
Hi all,
I think the heat has gotten to my brain, cause I've spent an hour without solving this one.
I'm in Broker5 trying to create an XML message. What I want is this:
Code: |
<!DOCTYPE MYCAT SYSTEM "my_cat.dtd">
<MYCAT version="1.0">
....
</MYCAT>
|
I don't get that one no matter how I play with (XML.DocTypeDecl) and the (XML.Attribute). Am I getting a conflict with my DoctypeDecl and my Root tag when doing something like this?
Code: |
SET OutputRoot.XML.(XML.DocTypeDecl)MYCAT = '';
SET OutputRoot.XML.(XML.DocTypeDecl).(XML.SystemId) = 'my_cat.dtd';
CREATE FIELD OutputRoot.XML.MYCAT;
SET OutputRoot.XML.MYCAT.(XML.Attribute)Version = '1.0';
|
Regards from summerland |
|
Back to top |
|
 |
kimbert |
Posted: Tue Jun 30, 2009 3:44 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
|
Back to top |
|
 |
elwis |
Posted: Tue Jun 30, 2009 4:13 am Post subject: |
|
|
Apprentice
Joined: 02 Apr 2008 Posts: 26 Location: Sweden
|
You are a better searcher then I am I didn't find anything useful at all.
I've read about the (XML.Element) before but thought there were an easier way then adding this text to 386 lines of code. But if there isn't, this one will at least work  |
|
Back to top |
|
 |
joebuckeye |
Posted: Tue Jun 30, 2009 6:22 am Post subject: |
|
|
 Partisan
Joined: 24 Aug 2007 Posts: 365 Location: Columbus, OH
|
You don't need to add it to 386 lines.
Build up the root of your XML document and then create a reference to the root or whatever part of the document you want to build from.
We use references all the time for building XML documents. Makes it easy to handle changes in the structure of the document. If a high level tag changes or a new level is added we only have to change the reference to that portion. All the references based on that reference stay the same.
References are your friend in ESQL. |
|
Back to top |
|
 |
kimbert |
Posted: Tue Jun 30, 2009 7:05 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
I've just realized what you meant. You only need to change one line, not 386 lines!
SET OutputRoot.XML.(XML.DocTypeDecl)MYCAT = '';
SET OutputRoot.XML.(XML.DocTypeDecl).(XML.SystemId) = 'my_cat.dtd';
CREATE FIELD OutputRoot.XML.MYCAT;
SET OutputRoot.XML.MYCAT.(XML.Attribute)Version = '1.0';
When the Compute node sees the second field reference to OutputRoot.XML.MYCAT it will assume that you are referring to the one which you created earlier. Instead of creating a new root element with name 'MYCAT' it will add the Version attribute to the DTD element.
That is why the XML writer was complaining about the missing root element.
When you specify OutputRoot.XML.(XML.Element)MYCAT, the path resolver cannot find any such element, and it creates a new one. Because that element has a suitable field type, it is a valid root for the output document - so no error.
btw, you should immediately change your code to use XMLNS. The XML domain is deprecated. Don't expect support from IBM if you continue to use it. ( I would advise XMLNSC, but you might need more DTD support than XMLNSC can provide ). |
|
Back to top |
|
 |
elwis |
Posted: Tue Jun 30, 2009 8:02 am Post subject: |
|
|
Apprentice
Joined: 02 Apr 2008 Posts: 26 Location: Sweden
|
Thanks for a very educating answer, I'll see if I can get a better solution then.
I'm using XML since the client wants the code to look like the old one, but perhaps I should be a little bit naughty here.. |
|
Back to top |
|
 |
Vitor |
Posted: Tue Jun 30, 2009 8:47 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
elwis wrote: |
I'm using XML since the client wants the code to look like the old one, but perhaps I should be a little bit naughty here.. |
Make a sucking sound through your teeth, while shaking your head & saying "I don't know, unsupported domain, obviously you're the client but I couldn't endorse it as a descision and frankly it's a bit risky......"
If you let your voice tail off right they'll be begging you to use a newer domain.
This site has been using a combination of XML & XMLNS (because XMLNSC "isn't compatable" ) with no ill effects. I'm still working on the right sucking sound to get XMLSNC.
Or the right wrist action with the trout..... _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
elwis |
Posted: Tue Jun 30, 2009 8:54 am Post subject: |
|
|
Apprentice
Joined: 02 Apr 2008 Posts: 26 Location: Sweden
|
I still haven't seen any man fail with a trout... |
|
Back to top |
|
 |
Vitor |
Posted: Tue Jun 30, 2009 8:57 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
elwis wrote: |
I still haven't seen any man fail with a trout... |
I need to pick my battles - this is a target rich environment & I'm wary of losing the "shock and awe" factor. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
|