4

I have a CRM entity XML message as follows:

<c:KeyValuePairOfstringanyType xmlns:c="ns1" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"  >
....
 <c:value i:type="**b:AliasedValue**" **xmlns:b="ns3"**>
 SomethingHere...
 </c:value>
</c:KeyValuePairOfstringanyType>

Then I deserialized it to an object and serialized back to xml
I get

<c:KeyValuePairOfstringanyType xmlns:c="ns1" xmlns:i="http://www.w3.org/2001/XMLSchema-   instance"  >
 <c:value i:type="b:AliasedValue" >
 SomethingHere...
</c:value>
</c:KeyValuePairOfstringanyType>

I loose the xmlns:b definition. Any idea why?

1
  • 1
    Just a guess (however somewhat educated), but the 'b' namespace isn't actually used in an element, just as a value in a attribute. Don't know too much about .net XML libs, but there should be an option to not strip "unused" namespaces
    – forty-two
    Commented Nov 30, 2012 at 18:54

1 Answer 1

0

forty-two is right: attribute values do not carry any default semantics, so the namespace usage isn't recognized as such by xml processors.

if you wish to refer to some b-data in your i:type-attribute, you my use a mapping element to associate c:value with a (hypothesized) b:value, i.e.:

<mapping xml:id="idXY'/>
...
<c:value c:ref="idXY">...</c:value>
...
<b:value b:ref="idXY">...</b:value>
...

... where you would declare _:ref as IDREF attributes in the respective xml schemas. you may have to adjust the design for 1:n-/m:n - mappings e.g. by having referrers as child elements of _:value.

best regards, carsten

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.