Closed Thomasb81 closed 1 month ago
Hi @Thomasb81 I think you should be using the Catalog model not the Component
from lxml import etree
from xsdata.formats.dataclass.parsers.handlers import LxmlEventHandler
from xsdata.formats.dataclass.parsers import XmlParser
from tgi2022.org.accellera.xmlschema.ipxact.mod_1685_2022 import Component, Catalog
from xsdata.formats.dataclass.serializers import XmlSerializer
ns = {'ipxact':"http://www.accellera.org/XMLSchema/IPXACT/1685-2022"}
raw = """<?xml version="1.0" encoding="UTF-8"?>
<ipxact:catalog xmlns:ipxact="http://www.accellera.org/XMLSchema/IPXACT/1685-2022" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.accellera.org/XMLSchema/IPXACT/1685-2022 http://www.accellera.org/XMLSchema/IPXACT/1685-2022/index.xsd" >
<ipxact:vendor>test.com</ipxact:vendor>
<ipxact:library>test_lib</ipxact:library>
<ipxact:name>catalog</ipxact:name>
<ipxact:version>1.0</ipxact:version>
</ipxact:catalog>"""
parser = XmlParser(handler=LxmlEventHandler)
catalogObj = parser.from_string(raw, Catalog)
print(catalogObj)
serializer = XmlSerializer()
serializer.config.indent = " "
print(serializer.render(catalogObj, ns_map=ns))
# <ipxact:catalog xmlns:ipxact="http://www.accellera.org/XMLSchema/IPXACT/1685-2022">
# <ipxact:vendor>test.com</ipxact:vendor>
# <ipxact:library>test_lib</ipxact:library>
# <ipxact:name>catalog</ipxact:name>
# <ipxact:version>1.0</ipxact:version>
# </ipxact:catalog>
Clear ! I figure out that I can even not specify the model:
Obj = parser.from_string(raw)
Th library will choose the right model ... it is written in the doc!
Thanks Thomas
Hello
I try to use xsdata library with following schema : http://www.accellera.org/XMLSchema/IPXACT/1685-2022/index.xsd
I generate the data model with following command:
This schema define 9 different root element![image](https://github.com/tefra/xsdata/assets/1123617/02a405c5-4897-4ea8-af69-901452d62544)
with following code:
dummy_catalog.xml
The tool produce:
Which is incorrect. If I render back the data, my root
<ipxact:catalog>
has been transform into<ipxact:component>
Soon as I try to load a document which is more specific, then the non compliance with schema is somehow report.
Is there a way to check root element or is that not in the scope of this library ? If not I should probably address this another dedicated library (lxml or xmlschema)
BR Thomas