0

One destination system requires that the xml for import contains xsi:schemaLocation="targetNS targetNS.xsd" as an attribute on the root node.

How can we accomplish this with BizTalk? Could it be done as a demand in the schema, by a map or do we have to use a pipeline?

The outgoing xml is suppose to look like this:

<?xml version="1.0" encoding="utf-8"?>
<root xmlns="targetNS" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="targetNS targetNS.xsd">
Martin Bring
  • 1,176
  • 1
  • 7
  • 17
  • I think they are confusing XML instances and XSD schemas, as xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" and xsi:schemaLocation is what you have in Schemas, not XML payloads – Dijkgraaf Apr 04 '22 at 04:53
  • That's not entirely true, is it? In a xml you can mark an element as nil which comes from "w3.org/2001/XMLSchema-instance", xsi:nil="true" for example. It could be abc:nil="true" as long as are declared with the namespace, xmlns:abc="w3.org/2001/XMLSchema-instance". – Martin Bring Jan 04 '23 at 13:07
  • The prefix can be choosen by the person/system creating the xml and need not be the same as the person/system consuming the xml. Using a parser and a namespacemanager you can "map" to any prefix you want, you don´t even have to know what the producer used. Otherwise it hade been quit hard to write generic xpath, if one had to be aware of what prefix other uses. You do need to know the namespaces though :) – Martin Bring Jan 04 '23 at 13:07

1 Answers1

1

The below schema will generate an attribute with the value at the root node. However the namespace prefix will be the default ns0: one, xmlns:xsi is Namespace (prefix) related attributes in XML and XML Schema (XSD). One of the settings to change from the default is the attributeFormDefault to qualified.

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="targetNS" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="root">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="test" type="xs:string" />
      </xs:sequence>
      <xs:attribute default="targetNS targetNS.xsd" name="schemaLocation" type="xs:string" />
    </xs:complexType>
  </xs:element>
</xs:schema>

Which generates as

<ns0:root ns0:schemaLocation="targetNS targetNS.xsd" xmlns:ns0="targetNS">
  <ns0:test>test_0</ns0:test>
</ns0:root>
Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54