I have an XML looking like this:
<?xml version="1.0" encoding="utf-8"?>
<n0:OrderConfirmation xmlns:n0="http://company.org/interface/MVSI"
xmlns:ord="urn:company.com:Order:XYZ:001">
<MessageHeader>
<ID>001</ID>
<CreationDateTime>2020-09-10T07:39:26.697Z</CreationDateTime>
</MessageHeader>
<Order>
<OrderID>00027847</SalesOrderID>
<Status>Confirmed</Status>
<Items>
<Article>
<ArticleID>ABC001</ArticleID>
<LineItem>000001</LineItem>
</Article>
</Items>
</Order>
</n0:OrderConfirmation>
I would say a better way would be to declare a default namespace like this:
<?xml version="1.0" encoding="utf-8"?>
<n0:OrderConfirmation xmlns:n0="http://company.org/interface/MVSI"
xmlns="urn:company.com:Order:XYZ:001">
<MessageHeader>
<ID>001</ID>
<CreationDateTime>2020-09-10T07:39:26.697Z</CreationDateTime>
</MessageHeader>
<Order>
<OrderID>00027847</SalesOrderID>
<Status>Confirmed</Status>
<Items>
<Article>
<ArticleID>ABC001</ArticleID>
<LineItem>000001</LineItem>
</Article>
</Items>
</Order>
</n0:OrderConfirmation>
Or more simplified: the root element could be part of the default namespace:
<?xml version="1.0" encoding="utf-8"?>
<OrderConfirmation xmlns="urn:company.com:Order:XYZ:001">
<MessageHeader>
<ID>001</ID>
<CreationDateTime>2020-09-10T07:39:26.697Z</CreationDateTime>
</MessageHeader>
<Order>
<OrderID>00027847</SalesOrderID>
<Status>Confirmed</Status>
<Items>
<Article>
<ArticleID>ABC001</ArticleID>
<LineItem>000001</LineItem>
</Article>
</Items>
</Order>
<OrderConfirmation>
because the n0
namespace value is global to the system and for all XML documents generated by the system.
I am wondering if this is a good practice in XML to let the middle elements in the "no-namespace" and alternatively to declare a namespace that is never used.
UPDATE: To give a better context of the situation, we are integrating different systems using an ESB in the whole enterprise. Systems can be in several departments across the company. In the actual situation we are transforming the incoming XML to a more normalized XML with a unique namespace related to the kind of data we're managing (an order in that case), like a canonical data model all other systems have to know about.