Thanks for the reply. I'll try to explain with an example below, and any help you can give would be much appreciated.

I generate the bindings like this:

$ pyxbgen -u shape.xsd -m shape
$ pyxbgen -u circle.xsd -m circle

Now the following code works (using the circle package):

from pyxb.utils import domutils
from circle import CreateFromDOM
p = CreateFromDOM(domutils.StringToDOM(open("example.xml").read()))

But this doesn't (using the shape package)

from pyxb.utils import domutils
from shape import CreateFromDOM
p = CreateFromDOM(domutils.StringToDOM(open("example.xml").read()))

Now in this case I could just use circle, but what if I add circle, pentagon, etc?
Because these are extensions I can't run pyxbgen on them all at once, and
because they're in different namespaces I shouldn't have to.

example.xml:

<?xml version="1.0"?>
<picture xmlns="http://www.example.com/shape";
         xmlns:c="http://www.example.com/circle";>
<name>Example Picture</name>
<shapes>
<square>
<size>5</size>
</square>
<c:circle>
<c:radius>10</c:radius>
</c:circle>
</shapes>
</picture>


shape.xsd:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
  targetNamespace="http://www.example.com/shape";
  xmlns="http://www.example.com/shape";
  elementFormDefault="qualified">

<xs:element name="picture">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="shapes" type="ShapesType"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:complexType name="ShapesType">
<xs:sequence>
<xs:element ref="shape" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:element name="shape" type="ShapeType"/>
<xs:complexType name="ShapeType"/>

<xs:element name="square" substitutionGroup="shape">
<xs:complexType>
<xs:complexContent>
<xs:extension base="ShapeType">
<xs:sequence>
<xs:element name="size" type="xs:int"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>

</xs:schema>

circle.xsd:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
  xmlns:shp="http://www.example.com/shape";
  targetNamespace="http://www.example.com/circle";
  xmlns="http://www.example.com/circle";
  elementFormDefault="qualified">
<xs:import namespace="http://www.example.com/shape"; schemaLocation="shape.xsd"/>

<xs:element name="circle" substitutionGroup="shp:shape">
<xs:complexType>
<xs:complexContent>
<xs:extension base="shp:ShapeType">
<xs:sequence>
<xs:element name="radius" type="xs:int"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:schema>


Thanks again, Sorry for the long post.

Jon

On 22/02/11 14:17, Peter Bigot wrote:
It's been a while since I've done anything with PyXB, so I may be rusty. But what you're describing is supposed to just work.

PyXB maintains a registry of known namespaces, which is initialized when a module is loaded. As a document is processed, the relevant namespace should be resolved and its content model used.

Although each module contains helper functions CreateFromDocument and CreateFromDOM, these should only provide a default namespace. You should be able to process a document that has full namespace information by using any of the CreateFromDOM functions. (The document must include the necessary xmlns:foo="uri" namespace declarations to map the namespace qualifiers to the actual namespaces which are URIs.)

If the document uses an absent namespace, then you have to use the CreateFromDOM function from the correct module, or identify the correct Namespace instance and provide it. (These functions also provide the option of overriding the default namespace, though I see a potential bug in that CreateFromDocument ignores it in favor of the module namespace.)

I thought I had some multiple namespace examples in the manual, but I don't see them offhand. From the distribution, examples/xsdprimer shows an example of a document that uses multiple namespaces, as would anything involving the OGC schema.

If you continue to have problems, please provide a pointer to a set of example schema and a document, along with the application code that isn't doing what you think it should, and I'll take a look.

Peter

On Tue, Feb 22, 2011 at 6:19 AM, Jon Siddle <j...@corefiling.co.uk <mailto:j...@corefiling.co.uk>> wrote:

    I'm looking at using pyxb for providing an extension mechanism and
    could
    do with some guidance.

    Say I have a.xsd which provides a namespace containing the head of a
    substitution group, and b.xsd which provides a separate namespace
    and contains elements which can be substituted.

    I can generate module a and module b, and I can successfully parse an
    xml file using b.CreateFromDOM but not a.CreateFromDOM.

    My problem is that b.xsd (and later c.xsd) will be introduced long
    after
    a.xsd. So once I've added c.xsd (module c), how do
    I process a file which contains substitutions from both b and c?

    I don't think this is specific to substitution groups at all. More
    generally, if I have an XML file containing multiple namespaces;
    how do
    I parse
    it?

    Jon

    
------------------------------------------------------------------------------
    Index, Search & Analyze Logs and other IT data in Real-Time with
    Splunk
    Collect, index and harness all the fast moving IT data generated
    by your
    applications, servers and devices whether physical, virtual or in
    the cloud.
    Deliver compliance at lower cost and gain new business insights.
    Free Software Download: http://p.sf.net/sfu/splunk-dev2dev
    _______________________________________________
    pyxb-users mailing list
    pyxb-users@lists.sourceforge.net
    <mailto:pyxb-users@lists.sourceforge.net>
    https://lists.sourceforge.net/lists/listinfo/pyxb-users



------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in 
Real-Time with Splunk. Collect, index and harness all the fast moving IT data 
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business 
insights. http://p.sf.net/sfu/splunk-dev2dev 
_______________________________________________
pyxb-users mailing list
pyxb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyxb-users

Reply via email to