Author |
Message
|
ceteareth |
Posted: Tue Feb 18, 2014 11:43 pm Post subject: XML to BLOB removed element prefix |
|
|
Acolyte
Joined: 12 Aug 2012 Posts: 51
|
I have read alot of post and other materials on the web but i still could not sort this out.
I am able to convert a XML into BLOB but the problem is the element prefix/namespace is removed. I would like to retain the prefix of the elements after being changed to BLOB. My xml looks something like below.
Input/Expected Output
<Person xmlns:ns1="xmlns="http://detail/detail" xmlns="http://detail/detail">
<ns1:name>my name</ns1:name>
<ns1:email>myname@email.com</ns1:email>
</Person>
Output:
<Person xmlns:ns1="xmlns="http://detail/detail" xmlns="http://detail/detail">
<name>my name</name>
<email>myname@email.com</email>
</Person>
I have a database node which has the following code. Hope someone could shine some light into this. Thanks in advance
Code: |
CREATE LASTCHILD OF RootRef DOMAIN('BLOB') NAME 'BLOB';
DECLARE options INTEGER BITOR( ValidateNone, RootBitStream );
SET RootRef.BLOB.BLOB = ASBITSTREAM( RootRef.XMLNSC OPTIONS options CCSID 1208);
SET RootRef.XMLNSC = NULL;
|
|
|
Back to top |
|
 |
mqsiuser |
Posted: Wed Feb 19, 2014 12:03 am Post subject: Re: XML to BLOB removed element prefix |
|
|
 Yatiri
Joined: 15 Apr 2008 Posts: 637 Location: Germany
|
This is not an "element prefix" but a "namespace prefix".
Probably you have to DECLARE and assign them explicity.
To your luck there are like 3 different ways to do it (there is an article in the info center about these) _________________ Just use REFERENCEs |
|
Back to top |
|
 |
ceteareth |
Posted: Wed Feb 19, 2014 12:56 am Post subject: |
|
|
Acolyte
Joined: 12 Aug 2012 Posts: 51
|
thanks for quick response mqsiuser.
I am currently searching through info center.
regarding the declare and assign explicity. does this mean that i have to set the namespace prefix on each element one by one? |
|
Back to top |
|
 |
mqsiuser |
Posted: Wed Feb 19, 2014 1:09 am Post subject: |
|
|
 Yatiri
Joined: 15 Apr 2008 Posts: 637 Location: Germany
|
|
Back to top |
|
 |
Gralgrathor |
Posted: Wed Feb 19, 2014 1:31 am Post subject: |
|
|
Master
Joined: 23 Jul 2009 Posts: 297
|
I suppose the parser sees no need to add a prefix when the elements concerned are *already* in the proper namespace through the definition of
Code: |
xmlns="http://detail/detail" |
I suspect that when you remove that definition the prefix will reappear.
By the way, I suppose that
Code: |
xmlns:ns1="xmlns="http://detail/detail" |
is a typo, right? |
|
Back to top |
|
 |
kimbert |
Posted: Wed Feb 19, 2014 1:47 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Please describe all of the nodes in your flow.
If the namespace prefixes are being 'removed' then they must have been there in the input message. The XMLNSC parser will not remove them unless your flow does something to make them get removed.
btw, your input XML looks wrong to me. Look at the xmlns attribute again. _________________ Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too. |
|
Back to top |
|
 |
mqsiuser |
Posted: Wed Feb 19, 2014 2:08 am Post subject: Re: XML to BLOB removed element prefix |
|
|
 Yatiri
Joined: 15 Apr 2008 Posts: 637 Location: Germany
|
WRONG:
ceteareth wrote: |
<Person xmlns:ns1="xmlns="http://detail/detail" xmlns="http://detail/detail">
<ns1:name>my name</ns1:name>
<ns1:email>myname@email.com</ns1:email>
</Person> |
BETTER:
Code: |
<Person xmlns:ns1="http://detail/detail" xmlns="http://detail/detail">
<ns1:name>my name</ns1:name>
<ns1:email>myname@email.com</ns1:email>
</Person> |
ALSO BETTER:
Code: |
<ns1:Person xmlns:ns1="http://detail/detail">
<ns1:name>my name</ns1:name>
<ns1:email>myname@email.com</ns1:email>
</ns1:Person> |
OR:
Code: |
<Person xmlns="http://detail/detail">
<name>my name</name>
<email>myname@email.com</email>
</Person> |
_________________ Just use REFERENCEs |
|
Back to top |
|
 |
ceteareth |
Posted: Mon Feb 24, 2014 12:12 am Post subject: |
|
|
Acolyte
Joined: 12 Aug 2012 Posts: 51
|
Sorry theres a typo on my previous post. heres a more correct and complete details.
Code: |
CREATE DATABASE MODULE BasicMessageFlow_Database
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
DECLARE RootRef REFERENCE TO Root;
CALL PrepareMessage(RootRef);
RETURN TRUE;
END;
CREATE PROCEDURE PrepareMessage(INOUT RootRef REFERENCE) BEGIN
-- Set XML string to element node
DECLARE XMLMESSAGE CHARACTER;
SET XMLMESSAGE = '<xml><name>name1</name></xml>';
SET RootRef.XMLNSC.*:Person.*:etc = XMLMESSAGE;
-- Create BLOB to hold the messag
CREATE LASTCHILD OF RootRef DOMAIN('BLOB') NAME 'BLOB';
DECLARE options INTEGER BITOR( ValidateNone, RootBitStream );
DECLARE BlobRef REFERENCE TO RootRef.BLOB;
SET BlobRef.BLOB = ASBITSTREAM( RootRef.XMLNSC OPTIONS options CCSID 1208);
-- Delete XMLNSC so that only BLOB would remain
SET RootRef.XMLNSC = NULL;
END;
END MODULE; |
Input
Code: |
<Person xmlns:ns1="http://www.ibm.com/persons" xmlns="http://www.ibm.com/persons">
<ns1:name>Person One</ns1:name>
<ns1:email>person.one@email.com</ns1:email>
<ns1:etc>etc</ns1:etc>
</Person> |
Output
Code: |
<Person xmlns:ns1="http://www.ibm.com/persons" xmlns="http://www.ibm.com/persons">
<name>Person One</name>
<email>person.one@email.com</email>
<etc><xml><name>name1</name></xml></etc>
</Person> |
|
|
Back to top |
|
 |
mqsiuser |
Posted: Mon Feb 24, 2014 1:30 am Post subject: |
|
|
 Yatiri
Joined: 15 Apr 2008 Posts: 637 Location: Germany
|
If you want the same thing, then hand it through as BLOB.
The ns-prefixes are removed, BUT your XML is "equivalent", because the default namespace (xmlns="http://www.ibm.com/persons") is "namespacing your elements" now:
Code: |
<Person xmlns="http://www.ibm.com/persons">
<name>Person One</name>
<email>person.one@email.com</email>
<etc><xml><name>name1</name></xml></etc>
</Person> |
So even without explicit "ns1:" the xml(-elements) is(are) logically the same.
Though there may be an option like "Always (use namespace) prefixes for xml-elements&attributes" or "don't use default namespace(s)"
But this option will likely prefix ALL you elements (including "Person"), which is not what you have as INPUT. _________________ Just use REFERENCEs |
|
Back to top |
|
 |
|