-
Notifications
You must be signed in to change notification settings - Fork 76
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
XMLSchemaConverter not able to convert the text data to xml #316
Comments
Probably related with the #315, if the content type is mixed. I will resolve them together, using some test cases as start. Thank you |
any update ? am getting other issues when am sending soap xml to json ,it is giving errors elif isinstance(obj, (converter.dict, dict)) and len(obj) == 1: <soapenv:Body xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wmb="urn:suncorp-com-au:wmb" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> |
I'm going to complete a set of tests with a fix for #315. About the default converter (XMLSchemaConverter, but also with UnorderedConverter, that is a variation of the default converter), you have to provide a In any case with mixed content the order of children cannot be preserved normally (cdata and child elements with the same name). For a warranty on preserving structure and order the only choice is to use the JsonML convention. |
See the below,the object is coming 3
-> elif isinstance(obj, (converter.dict, dict)) and len(obj)==1:
(Pdb) n
/Users/priyatamnayak/.local/share/virtualenvs/nano-lixi-IJd-8ihv/lib/python3.8/site-packages/xmlschema/validators/schemas.py(2112)iter_encode()
-> if not isinstance(xsd_element, XsdElement):
(Pdb) len(obj)
3
(Pdb) converter
<xmlschema.converters.jsonml.JsonMLConverter object at 0x10c1d4ac0>
(Pdb)
From: Priyatam Nayak ***@***.***>
Date: Wednesday, 6 July 2022 at 10:47 pm
To: sissaschool/xmlschema ***@***.***>, sissaschool/xmlschema ***@***.***>
Cc: Author ***@***.***>
Subject: Re: [sissaschool/xmlschema] XMLSchemaConverter not able to convert the text data to xml (Issue #316)
Have also tested with JsonML ,it is giving issues for soap xml ,any idea ?
Get Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: Davide Brunato ***@***.***>
Sent: Wednesday, July 6, 2022 10:44:51 PM
To: sissaschool/xmlschema ***@***.***>
Cc: Priyatam Nayak ***@***.***>; Author ***@***.***>
Subject: Re: [sissaschool/xmlschema] XMLSchemaConverter not able to convert the text data to xml (Issue #316)
I'm going to complete a set of tests with a fix for #315<#315>. About the default converter (XMLSchemaConverter, but also with UnorderedConverter, that is a variation of the default converter), you have to provide a cdata_prefix (usulally '#').
In any case with mixed content the order of children cannot be preserved normally (cdata and child elements with the same name). For a warranty on preserving structure and order the only choice is to use the JsonML convention.
—
Reply to this email directly, view it on GitHub<#316 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AYU3RVE4MO5UF3KZJQMTVETVSV5UHANCNFSM52NIROPA>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Am getting the below error when am using jsonMLconverter and also the len(obj) is coming 3
File "/Users/priyatamnayak/Repository/nano-lixi/src/lixi/base.py", line 140, in to_xml
return parser.to_xml()
File "/Users/priyatamnayak/Repository/nano-lixi/src/lixi/partners/nikola_v14/__init__.py", line 187, in to_xml
xml_data = xmlschema.from_json(
File "/Users/priyatamnayak/.local/share/virtualenvs/nano-lixi-IJd-8ihv/lib/python3.8/site-packages/xmlschema/documents.py", line 413, in from_json
return schema.encode(obj, path=path, converter=converter, **kwargs)
File "/Users/priyatamnayak/.local/share/virtualenvs/nano-lixi-IJd-8ihv/lib/python3.8/site-packages/xmlschema/validators/schemas.py", line 2136, in encode
for result in self.iter_encode(obj, path, validation, *args, **kwargs):
File "/Users/priyatamnayak/.local/share/virtualenvs/nano-lixi-IJd-8ihv/lib/python3.8/site-packages/xmlschema/validators/schemas.py", line 2114, in iter_encode
if path is not None:
xmlschema.validators.exceptions.XMLSchemaEncodeError: failed validating ['soapenv:Body', {'xmlns:soapenc': 'http://schemas.xmlsoap.org/soap/encoding/', 'xmlns:soapenv': 'http://schemas.xmlsoap.org/soap/envelope/', 'xmlns:wmb': 'urn:suncorp-com-au:wmb', 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xmlns:wsse': 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'xmlns:
From: Priyatam Nayak ***@***.***>
Date: Wednesday, 6 July 2022 at 10:51 pm
To: sissaschool/xmlschema ***@***.***>, sissaschool/xmlschema ***@***.***>
Cc: Author ***@***.***>
Subject: Re: [sissaschool/xmlschema] XMLSchemaConverter not able to convert the text data to xml (Issue #316)
See the below,the object is coming 3
-> elif isinstance(obj, (converter.dict, dict)) and len(obj)==1:
(Pdb) n
/Users/priyatamnayak/.local/share/virtualenvs/nano-lixi-IJd-8ihv/lib/python3.8/site-packages/xmlschema/validators/schemas.py(2112)iter_encode()
-> if not isinstance(xsd_element, XsdElement):
(Pdb) len(obj)
3
(Pdb) converter
<xmlschema.converters.jsonml.JsonMLConverter object at 0x10c1d4ac0>
(Pdb)
From: Priyatam Nayak ***@***.***>
Date: Wednesday, 6 July 2022 at 10:47 pm
To: sissaschool/xmlschema ***@***.***>, sissaschool/xmlschema ***@***.***>
Cc: Author ***@***.***>
Subject: Re: [sissaschool/xmlschema] XMLSchemaConverter not able to convert the text data to xml (Issue #316)
Have also tested with JsonML ,it is giving issues for soap xml ,any idea ?
Get Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: Davide Brunato ***@***.***>
Sent: Wednesday, July 6, 2022 10:44:51 PM
To: sissaschool/xmlschema ***@***.***>
Cc: Priyatam Nayak ***@***.***>; Author ***@***.***>
Subject: Re: [sissaschool/xmlschema] XMLSchemaConverter not able to convert the text data to xml (Issue #316)
I'm going to complete a set of tests with a fix for #315<#315>. About the default converter (XMLSchemaConverter, but also with UnorderedConverter, that is a variation of the default converter), you have to provide a cdata_prefix (usulally '#').
In any case with mixed content the order of children cannot be preserved normally (cdata and child elements with the same name). For a warranty on preserving structure and order the only choice is to use the JsonML convention.
—
Reply to this email directly, view it on GitHub<#316 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AYU3RVE4MO5UF3KZJQMTVETVSV5UHANCNFSM52NIROPA>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
- Check also for #316 (is a misconfiguration, not a bug) - Fix etree_elements_assert_equal() testing helper
I'm sorry, but Is difficult to follow issue if you not provide a clear explanation of the case, with XML data and at least the relevant part of the XSD schema. Also please avoid replying by email, use web form and format data content instead. Thank you |
xs = xmlschema.XMLSchema(
self.xsd_file, converter=xmlschema.JsonMLConverter(dict_class=dict)
)
xs.import_schema(
namespace=self.location, location=self.location, build=True
)
self.data = xs.to_dict(self.xml_file, unordered=True)
xs = xmlschema.XMLSchema(
self.xsd_file,
converter=xmlschema.JsonMLConverter(dict_type=dict),
)
xs.import_schema(
namespace=self.location, location=self.location, build=True
)
json_data = json.dumps(self.data)
xml_data = xmlschema.from_json(
json_data,
xs,
unordered=True,
converter=xmlschema.JsonMLConverter(dict_type=dict),
preserve_root=True,
namespaces={
'soapenv': 'http://schemas.xmlsoap.org/soap/envelope/',
}, |
Tried your lines of code, retrieving soapenv schema from https://schemas.xmlsoap.org/soap/envelope/. You miss to provide the path argument, eg.: xml_data = xmlschema.from_json(json_data, xs, path='soapenv:Body', unordered=True, converter=xmlschema.JsonMLConverter(dict_type=dict), preserve_root=True, namespaces={ 'soapenv': 'http://schemas.xmlsoap.org/soap/envelope/'}) xml_data is identical to xml source data (nikola_valid.xml). The file nikola_valid.xml contains an invalid character I check if it is possible to retrieve the right encoding element with a full search into defined global elements. |
yes, have changed the encoding. 79 if not isinstance(obj, MutableSequence): |
Aslo want to keep namespace tag as and but the xml_from_json converting it like below . How to keep it is as original format ? |
Provide a full namespace map (not only 'soapenv' ...) when you call decode/to_dict. Best regards |
Have given that, but it is becoming ns2 instead of ns0 <soapenv:Body xmlns:ns2="urn:ais:schema:banking:loans:sunloan:SubmitSLNApplication" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wmb="urn:suncorp-com-au:wmb"> @brunato any idea ? |
json_data = json.dumps(self.data)
|
You cannot use 'ns0', 'ns1' ... prefixes in the map because they are reserved (by ElementTree) |
Then how can i achieve this ? <soapenv:Body xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wmb="urn:suncorp-com-au:wmb" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> |
i think this is the issue why xmlns keeping ns0': 'urn:ais:schema:banking:loans:sunloan:SubmitSLNApplication'}, instead of it should present in 'ns0:ApplicationBatch ' dict ? lx.to_dict()['@xmlns'] |
after removing from that it is giving correct result, do you know how can put that inside applicationbatch at the time dict creation ? |
any idea @brunato |
This ns0': 'urn:ais:schema:banking:loans:sunloan:SubmitSLNApplication' is coming as @xlmns attribute ,instead of {'ns0:ApplicationBatch': [{'@NumberOfApplications': '1', '@productiondata': 'No', 'ns0:Identifier': [{'@uniqueid': '1036921-SUN', '@type': 'BrokerAssigned'}], {'@xmlns': {'soapenc': 'http://schemas.xmlsoap.org/soap/encoding/', 'soapenv': 'http://schemas.xmlsoap.org/soap/envelope/', 'wmb': 'urn:-com-au:wmb', 'xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'wsse': 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'ns0': 'urn:ais:schema:banking:loans:oan:SubmitSLNApplication'}, 'soapenv:Body': {'soapenv:Envelope': [{'soapenv:Header': {'wmb:ServiceName': [{'$': 'LOAN'}], 'wmb:Action': [{'$': 'SUBMITAPPLICATION'}]}, 'soapenv:Body': {'ns0:ApplicationBatch': [{'@NumberOfApplications': '1', '@productiondata': 'No', 'ns0:Identifier': [{'@uniqueid': '1036921-SUN', '@type': 'BrokerAssigned'}], |
Have also tested with JsonML ,it is giving issues for soap xml ,any idea ?
Get Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: Davide Brunato ***@***.***>
Sent: Wednesday, July 6, 2022 10:44:51 PM
To: sissaschool/xmlschema ***@***.***>
Cc: Priyatam Nayak ***@***.***>; Author ***@***.***>
Subject: Re: [sissaschool/xmlschema] XMLSchemaConverter not able to convert the text data to xml (Issue #316)
I'm going to complete a set of tests with a fix for #315<#315>. About the default converter (XMLSchemaConverter, but also with UnorderedConverter, that is a variation of the default converter), you have to provide a cdata_prefix (usulally '#').
In any case with mixed content the order of children cannot be preserved normally (cdata and child elements with the same name). For a warranty on preserving structure and order the only choice is to use the JsonML convention.
—
Reply to this email directly, view it on GitHub<#316 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AYU3RVE4MO5UF3KZJQMTVETVSV5UHANCNFSM52NIROPA>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
this converter is able to convert the below xml data to dict data
But not able to convert back to xml when am using from_json
The text was updated successfully, but these errors were encountered: