ElementTree xmlns:xsi question

Fredrik Lundh fredrik at pythonware.com
Wed Nov 29 01:51:00 EST 2006


Craig wrote:

> I'm generating an XML script using ElementTree which has the following
> attributes in the root element:
> 
> <CANmessages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>  xsi:noNamespaceSchemaLocation="code/can.xsd">

those are namespace declarations, and mean that tags prefixed by "xsi" 
really belongs to the http://www.w3.org/2001/XMLSchema-instance name-
space.

> My python script I have written is:
> 
> root = Element("CANmessages",
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance",
> xsi:noNamespaceSchemaLocation="code/can.xsd")

try:

NS_XSI = "{http://www.w3.org/2001/XMLSchema-instance}"

root = Element("CANmessages")
root.set(NS_XSI + "noNamespaceSchemaLocation", "code/can.xsd")

also see:

     http://effbot.org/zone/element.htm#xml-namespaces

</F>




More information about the Python-list mailing list