-
Notifications
You must be signed in to change notification settings - Fork 73
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
question: how to enumerate annotations #366
Comments
Hi, >>> import xmlschema
>>> schema = xmlschema.XMLSchema("<your schema source>")
>>>
>>> for c in schema.iter_components(xsd_classes=xmlschema.XsdComponent):
... if c.annotation is not None:
... print(c.annotation.appinfo)
... print(c.annotation.documentation) For iterating over all loaded schemas you can use: >>> for c in schema.maps.iter_components(xsd_classes=xmlschema.XsdComponent):
... if c.annotation is not None:
... print(c.annotation.appinfo)
... print(c.annotation.documentation) Note: currently the annotation property is not defined for schema objects, this is why I use the filter |
Grazie mille per la risposta rapida! Unfortunately I still have an issue: I forgot to mention that (beside I'm new to both xsd and xmlschema) I had to use v1.1 (which leaded me to use your library) because I heard that it's the version that permits more than 1 maxOccurs as element attribute value in a So following your example I came up with a schema = xmlschema.XMLSchema11(args.schema)
for c in schema.iter_components(xsd_classes=xmlschema.XsdComponent):
if c.annotation is not None:
for item in c.annotation.documentation:
print(item.text) but I get an error expand
|
I don't understand where the The repetitions are originated by implicit internals attribute groups that share the same elem with correspondant complex types. It should be fixed with a redefinition of the property that parse the annotation. Thank you |
isn't because of my wrong maxOccurs="3" in the highlighted line? So I can convert the resulting list to a set as workaround, but now I wonder also how I can permit the font element to be repeated 3 times with 3 different attributes ( I don't even know if this is correct in XML, though it works). |
anyway maxOccurs="3" is admitted with XSD 1.1. For clarity this is the schema parsing results for me: >>> import xmlschema
>>> schema = xmlschema.XMLSchema11('rc.xsd')
>>> schema = xmlschema.XMLSchema('rc.xsd')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/brunato/Development/projects/xmlschema/xmlschema/validators/schemas.py", line 464, in __init__
self.parse_error(e.reason or e, elem=e.elem)
File "/home/brunato/Development/projects/xmlschema/xmlschema/validators/xsdbase.py", line 190, in parse_error
raise error
xmlschema.validators.exceptions.XMLSchemaParseError: attribute maxOccurs='3': value must be one of [0, 1]:
Schema:
<xs:element xmlns:xs="http://www.w3.org/2001/XMLSchema" name="font" type="labwc:font" minOccurs="0" maxOccurs="3" />
Path: /xs:schema/xs:complexType[13]/xs:all/xs:element[4]
Using sets is correct with translation strings, because there could be the same description in different components. |
First of all, thank you very much to work on this!
So the syntax is correct? Thank you for the confirmation!
Right!
Nice!
I came out with a working Qt translation for XSD, the only issue remains is the underlined one: <xs:simpleType name="fontplace">
<xs:restriction base="xs:string">
<xs:enumeration value="ActiveWindow">
<xs:annotation><xs:documentation>Titlebar of active window</xs:documentation></xs:annotation>
</xs:enumeration>
<xs:enumeration value="MenuItem">
<xs:annotation><xs:documentation>Menu item label (currently only root menu)</xs:documentation></xs:annotation>
</xs:enumeration>
<xs:enumeration value="OnScreenDisplay">
<xs:annotation><xs:documentation>Items in the on screen display</xs:documentation></xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType> finds only Let me know if there is something to open a single issue for, for a later resolution time and avoid confusion in this one. |
This because it accesses also to XSD meta-schema annotations. Maybe there should be a specific method for extracting all annotations, with various filtering choices.
There are also other cases to consider. For example in this chunk: <xs:simpleType name="fontplace">
<xs:restriction base="xs:string">
<xs:enumeration value="ActiveWindow">
<xs:annotation><xs:documentation>Titlebar of active window</xs:documentation></xs:annotation>
</xs:enumeration>
<xs:enumeration value="MenuItem">
<xs:annotation><xs:documentation>Menu item label (currently only root menu)</xs:documentation></xs:annotation>
</xs:enumeration>
<xs:enumeration value="OnScreenDisplay">
<xs:annotation><xs:documentation>Items in the on screen display</xs:documentation></xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType> there could be annotations also on
It could help a PR contribution with a full annotated XSD schema (or several smaller fully annotated schemas) that can be used for building tests an then to fix the code. |
I don't know much well the system yet, I only expect that an user xsd should be parsed to extract only his data, not the "system' libraries" one
to me the question is, in other words respect what I said above, how can I retrieve only the data I specified in my schema file/namespace?
that sounds a simple task I can do, but I have no idea ATM about which specific cases I should reproduce |
Meta-schema is not a library but only a set of base schemas for validating XSD sources.
you can iterate all the schemas of the global maps instance (using iter_schemas()) and filter them on the
a case that summarizes the annotations of your effective XML case(s) maybe sufficient |
Sorry for the delay. The script works by |
Hi, |
Hello, OK, thank you! |
Hi, Try that and report me any problem on using the new feature. Thank you |
Thank you for the work! I'll take a bit to finish some projects work, I'll try and let you know if solved ASAP. |
Hello, I would like to access all the
xs:documentation
content to export for translation, but I wasn't able to.From the read the docs I see in the API there is a XsdAnnotation class that owns both
appinfo
anddocumentation
.I tried also with plain xml.etree.ElementTree to parse the file without success.
The text was updated successfully, but these errors were encountered: