How to insert a xml element from another namespace as a child and still be a valid xml?
I have the following xml file
<Layout xmlns="http://tempuri.org/Layout/">
<Numeric Id="temperature" Caption="Temperature">
开发者_运维百科<validation:IsValidWhen xmlns:validation="http://tempuri.org/Validation/">
</validation:IsValidWhen>
</Numeric>
</Layout>
The http://tempuri.org/Layout/
XSD does not have a reference to http://tempuri.org/Validation/
and I cannot change it.
I am getting the error
The element 'Numeric' in namespace 'http://tempuri.org/Layout/' has invalid child element 'IsValidWhen' in namespace 'http://tempuri.org/Validation/'. List of possible elements expected: 'ContextMenu, OnChanged, OnLeave' in namespace 'http://tempuri.org/Layout/'
How can I make this XML be valid when the parent element is from a schema that is not aware of my validation schema?
If you do not control the http://tempuri.org/Layout/
schema, then there may not be anything you can do to make this "valid." However, it's still perfectly reasonable and well-formed XML that can be used by any party that knows what to expect. If the other parties you're interacting with understand the format, there really isn't any problem.
Perhaps you can use XML catalogs to instruct your tools (or code, which has strict validation) where to locate multiple unrelated schemas.
精彩评论