How to map two differnt namespace documents.

Hi All,

I need to map two documents which were created using two different XML schemas (i.e, two diffrent namespace and two different prefix (ns: and tns:)). How do I map them?

Should we map element by element? OR are there any services available? I am kinda new to XML mappings. I appreciate any help.

Thanks,
Gany

Hi Gany,

if you need the namespaces (and they point to different definitions), i think yes. But if you do not need them (you do not validate your message), just remove them, and make one mapping.

Rob

Rob,

Thanks for reply. I have a situation…

Message1
ns:msg1
ns:fld1
ns:fld2

where ns=http://abc.com

Messge2
tns1:msg1
tns1:fld1
tns1:fld2

where tns1=http://xyz.com

These two messages are in two different namespaces. Both of them are created using two diffent xsd schemas. How do we map them (each has lot of fields including documents and document lists). If there is no data in those documents lists has @xsi:nil etc. I am guessing there must be some easy mapping using xml technics (XSLT) or so. As I mentioned, I am new to XML mappings. I appreciate your help.

Thanks,
Gany

Normally, when the creators of two documents specify different XML namespaces they do so intentionally to indicate clearly that the two documents do not define elements which may have thes same name in the same way (e.g ns:fld1 does not refer to the same thing as tns1:fild1).

It would be incorrect to just map documents from different namespaces together without knowing for sure that they each element refers to the same thing.

If the documents do refer to the same thing and you know that each field in the first is defined in the same way in the second, then you might be able to do the following assuming that each is created from an xml string:

  1. Use pub.xml:xmlStringToNode to create a node from the first xml string. Set isXML to “true”.
  2. Use pub.xml:xmlNodeToDocument to create a document named “doc1”. Populate the nsDecls parameter with a new prefix “def”, but specify the namespace from the first string (“http://abc.com” in your example"). The document will contain fields named def:fld1 and def:fld2.
  3. Repeat steps 1 and 2 for the second xml string, but populate nsDecls with the prefix “def” and the namespace from the second string (“http://xyz.com” in your example). Name the resulting document “doc2”.
  4. Now both doc1 and doc2 contain fields named def:fld1 and def:fld2. You can map directly from doc1 to doc2 and values for def:fld1 and def:fld in doc2 would be replaced by those in doc1.

HTH,

Mark

Are you mapping data from these two different docs into 1? Or are you just mapping from one to the other?

Thanks for reply.

Sorry! I was struck with something else for two days. Actually, I need to map data from one document to another. I did it element by element as a work around. I feel there should be a better way to map them. Please advice me.

Thanks,
Gany

That’s not a work around. That is the way to map them. You’re on the right path.

What “better” way would you envision?

I think he wants to map from parent-level docs and not down at the leaf nodes. If he follows my steps above to “normalize” the prefixes, I think he could do that.

Mark

Ah, I see. Gany, you’ll need to be careful about mapping at the document level. After the mapping, both docs will point to the same internal structure. Changes in one will affect the other, since mapping at the document level copies by reference, not by value. If the source document is dropped after mapping and not processed any further, you should be okay. Just wanted you to be aware of the behavior.

Thanks for reply!

First thing I tried was changing the namespace prefix as Mark explained and map at parent level. It appeared my problem solved. But it failed while validating the XML (unknown reason probably namespace or prefix).

Then tried by replacing the prefix in xmlstring and convert to document. I guess namespace did not allow me.

Finally, mapped element by element. It looks fine and works well. BUT…

As schema element defined nillable some times it we do not have data it comes as @xsi:nil etc., I can not really map exactly to the target document. OR bottom line… After mapping those two documents do not look alike. Only the elements which has data look a like.

I guess, as Mark adviced (which was my first attempt before posting here), I need to go back and check the cause for failing the validation.

i.e
pub.xml:documentToXMLString
pub.xml:xmlStringToXMLNode
pub.xml:XMLNodeToDocument

then map

Once again my intention is to map Doc1 to Doc21 in the following…

Doc1
Doc1
fld1
fld2

Doc2
Doc2
Doc21
fld1
fld2
Doc22
fld22
fld23

As they are two different schemas, we have two different documents and two different namespaces with their own prefixs… One of them part of another; so, I need to map that part exactly then add other elements data to complete the mapping and proceed further.

I appreciate your reponses.

Thanks,
Gany