Author |
Message
|
_Angus_ |
Posted: Fri Feb 13, 2009 3:03 am Post subject: Converting char to XML |
|
|
 Acolyte
Joined: 25 Apr 2005 Posts: 54 Location: Edinburgh
|
I'm trying to think of an ESQL way of converting an XML string to XML. For example:
SET Environment.myXML = '<Top><Angus>Hello</Angus></Top>';
... which will obviously just assign the string value to the myXML element. It would be nice to have:
SET Environment.myXML = CAST('<Top><Angus>Hello</Angus></Top>' AS XML);
but unfortunately that doesn't exist. I've tried to work how to do it using CREATE with PARSE but not succeeded yet!
Any help, pointers or suggestions would be much appreciated
Angus _________________ *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Angus Cooke ~ AngusSoft
Integration Development Tools
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* |
|
Back to top |
|
 |
kimbert |
Posted: Fri Feb 13, 2009 3:15 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
CASTing and parsing are completely different things. CAST converts from one scalar type to another scalar type. Parsing converts a bitstream to a message tree.
If you use the search button you will find dozens of examples on this forum of how to use CREATE...PARSE. I expect you forgot to specify a CCSID and ENCODING, but you haven't told us what problems you encountered - so I have to guess. |
|
Back to top |
|
 |
dk27 |
Posted: Fri Feb 13, 2009 3:19 am Post subject: |
|
|
Acolyte
Joined: 28 Apr 2008 Posts: 51
|
Can you plz try this?
DECLARE inCCSID INT InputProperties.CodedCharSetId;
DECLARE inEncoding INT InputProperties.Encoding;
DECLARE inBitstream BLOB ASBITSTREAM('<Top><Angus>Hello</Angus></Top>', inEncoding, inCCSID);
CREATE LASTCHILD OF OutputRoot DOMAIN('XML')
PARSE(inBitStream, inEncoding, inCCSID, 'DP3UK14002001',
'TestCase', 'XML1', options);
Reg,
D |
|
Back to top |
|
 |
kimbert |
Posted: Fri Feb 13, 2009 3:29 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
dk27: why are you recommending the use of the deprecated XML domain? |
|
Back to top |
|
 |
Vitor |
Posted: Fri Feb 13, 2009 3:33 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
|
Back to top |
|
 |
_Angus_ |
Posted: Fri Feb 13, 2009 3:34 am Post subject: |
|
|
 Acolyte
Joined: 25 Apr 2005 Posts: 54 Location: Edinburgh
|
Yes I know casting and parsing are different - that wasn't a serious suggestion!
An example of CREATE ... PARSE using Unicode of my example above would be nice. I haven't tried anything yet, I just couldn't work out an easy syntax for what I wanted to do from the CREATE syntax doc. The XML string will be in a CHARACTER variable. _________________ *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Angus Cooke ~ AngusSoft
Integration Development Tools
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* |
|
Back to top |
|
 |
kimbert |
Posted: Fri Feb 13, 2009 5:04 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
An example of CREATE ... PARSE using Unicode of my example above would be nice |
The online docs contain examples. Please at least make an attempt to solve this yourself. If you still cannot make it work, please tell us what you tried, and what happened. |
|
Back to top |
|
 |
_Angus_ |
Posted: Fri Feb 13, 2009 7:17 am Post subject: |
|
|
 Acolyte
Joined: 25 Apr 2005 Posts: 54 Location: Edinburgh
|
Indeed - as my plan to get some quick help on here failed I've already been working it out myself.
DECLARE AuditAdminXml CHARACTER '<Top><Angus>Hello</Angus></Top>';
DECLARE xmlBlob BLOB CAST(AuditAdminXml AS BLOB CCSID 1200);
CREATE LASTCHILD OF Environment.AuditAdmin DOMAIN ('XMLNS') PARSE (xmlBlob, 0, 1200);
... does exactly what I need if anyone else finds this useful.
Cheers
Angus _________________ *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Angus Cooke ~ AngusSoft
Integration Development Tools
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Feb 13, 2009 7:22 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Well, it's close.
You forgot a C.
Please don't use the XMLNS domain...  |
|
Back to top |
|
 |
_Angus_ |
Posted: Fri Feb 13, 2009 7:55 am Post subject: |
|
|
 Acolyte
Joined: 25 Apr 2005 Posts: 54 Location: Edinburgh
|
Yup, I have changed it to the compact parser (and utf-8 ) but purely for performance reasons. The XML I'm manipulating is just naked XML so I don't care about any extras. I know the XML parser is bad but how bad is the XMLNS one?!  _________________ *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Angus Cooke ~ AngusSoft
Integration Development Tools
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Feb 13, 2009 7:58 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
_Angus_ wrote: |
I know the XML parser is bad but how bad is the XMLNS one?!  |
It's not "bad", per se.
But it's on the order of 400% slower... why drive a ten year old car when you can drive a Veyron? |
|
Back to top |
|
 |
kimbert |
Posted: Fri Feb 13, 2009 8:45 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Glad you got it working.
I expect you're aware that some CREATE LASTCHILD statements would have done the same job at least as quickly, but I presume you are doing it this way for readability /maintainability. |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Feb 13, 2009 9:03 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
I expect that the actual XML he needed to parse wasn't quite so simple...  |
|
Back to top |
|
 |
|