I am trying to dynamically create xml schemas with php but I'm having trouble with the namespace. What I want to do is have a function return the xsd:elements and add them to the xsd:sequence nodes.
I create the xsd:element nodes in a temporary DOMDocument in the function, I need to specify the xsd namespace "xmlns:xsd="http://www.w3.org/2001/XMLSchema" otherwise the 'xsd:' bit is removed. I then extract the required node form the temporaty document and use importNode() to copy to the existign DOMDocument. the problem is that the full xmlns string is attached to EVERY node that is returned form the function that creates the elements.
Initial DOMDocument
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="UserType">
<xsd:sequence>
// add elements here
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Temp DOMDocument I use to collect fields
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element type="xsd:string" name="Field1"/>
<xsd:element type="xsd:string" name="Field2"/>
<xsd:element type="xsd:string" name="Field3"/>
</xsd:schema>
What I get
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
<xsd:complexType name="UserType"/>
<xsd:sequence/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" type="xsd:string" name="Field1"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" type="xsd:string" name="Field2"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" type="xsd:string" name="Field3"/>
</xsd:sequence/>
</xsd:complexType/>
</xsd:schema/>
How do I import into an existing namespace?
?/>
at the end... Is that a typo? – Andreas Wong