Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document cannot be decoded #491

Closed
skinkie opened this issue May 12, 2021 · 9 comments
Closed

Document cannot be decoded #491

skinkie opened this issue May 12, 2021 · 9 comments

Comments

@skinkie
Copy link
Contributor

skinkie commented May 12, 2021

I am trying to move more projects from generateDS towards xsdata. For the SMIL standard I am using a DTD that is converted via trang to an XSD. I have attempted to use the optimize-datatypes branch and master branch. Both of them generate code, but neither of them allow me to parse a document. The structure remains "empty".

from xsdata.formats.dataclass.parsers.config import ParserConfig
config = ParserConfig(
     process_xinclude=False,
     fail_on_unknown_properties=False,
)

from xsdata.formats.dataclass.context import XmlContext
from xsdata.formats.dataclass.parsers import XmlParser

from smil import Smil

import sys

file = sys.argv[1]
parser = XmlParser(context=XmlContext(), config=config)
pd = parser.parse(file, Smil)
print(pd.head)

smil.py.txt
broadcast.smil.txt

@tefra
Copy link
Owner

tefra commented May 12, 2021

Can you share the xsd? If you switch on the config fail_on_unknown_properties you will see that the parser fails to match an element to the a model field.

  1. The root element namespace in the xml doesn't match the generated model, it should be like this in order to work.
@dataclass
class Smil(SmilSmilContent):
    class Meta:
        name = "smil"
        namespace = "http://www.w3.org/ns/SMIL"
  1. I need to put the name Meta in the reserved words
class SmilHeadContent:
    class Meta:
        name = "SMIL.head.content"

    meta: List[Meta] = field(  # There is an actual dataclass with name Meta 
        default_factory=list,
        metadata={
            "name": "meta",
            "type": "Element",
        }
    )

@skinkie
Copy link
Contributor Author

skinkie commented May 12, 2021

generated-xsd.zip

@tefra
Copy link
Owner

tefra commented May 12, 2021

There is no namespace http://www.w3.org/ns/SMIL in those schemas, the models are generated correctly...

for the name conflict switch to branch issue-491

@skinkie
Copy link
Contributor Author

skinkie commented May 12, 2021

There is no namespace http://www.w3.org/ns/SMIL in those schemas, the models are generated correctly...

for the name conflict switch to branch issue-491

When searching for this, I noticed a namespace prefix in my generateDS session. That explains why it works. Maybe a command line argument to specify it makes sense.

@tefra
Copy link
Owner

tefra commented May 12, 2021

generateDS allows to switch the default namespace of the schema under what context? The schema is supposed to be a binding contract, either the schema is wrong or the xml.

@skinkie
Copy link
Contributor Author

skinkie commented May 12, 2021 via email

@skinkie
Copy link
Contributor Author

skinkie commented May 12, 2021 via email

@tefra
Copy link
Owner

tefra commented May 12, 2021

Yeah I suggest fixing the schema instead or the conversion from the DTD,

the fix for the name conflict is merged on master #492

@skinkie
Copy link
Contributor Author

skinkie commented May 12, 2021

Added targetNamespace, most of the problems have been resolved. The remaining ConverterWarning's are likely generated between chair and keyboard.

@skinkie skinkie closed this as completed May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants