Questions tagged [python-xmlschema]

Use for questions about the xmlschema Python library for processing XML Schema based files and XML data.

The xmlschema library is an XML Schema validator and data conversion library for Python.

Asking Questions:

  • Before asking a question, make sure you have read the usage section of the documentation and API docs.

  • Please provide an example of XML data and details of relevant XML Schema (if appropriate) in your question.

Usage

Import the library, create a schema instance using the path of the file containing the schema as an argument, and then validate an XML instance file.

import xmlschema
my_schema = xmlschema.XMLSchema('vehicles.xsd')

# validate() raises exception if fails
my_schema.validate('vehicles.xml')

# or call is_valid() which returns True or False
valid = my_schema.is_valid('vehicles.xml')

Useful links:

See also:

26 questions
3
votes
1 answer

Generate consistent JSON from XML for sometimes repeated elements with xmltodict

For converting XML to JSON with python, several methods exist which usually boil down to the same principle. The most referred method today is xmltodict. I'm trying to convert multiple xml documents to JSON, but run into issues if elements that are…
Jeroen
  • 452
  • 5
  • 12
3
votes
1 answer

Element is not an element of the schema

I want to validate an XML file from my bank against an iso20022 XSD, but it fails claiming the first element (Document) is not an element of the scheme. I can see the 'Document' element defined in the XSD though. I downloaded the XSD mentioned in…
vollkorn
  • 33
  • 4
2
votes
1 answer

I am trying to make a SOAP request with python and zeep

I am trying to make a SOAP request with python and zeep, I need to add a soap:Header with the security (wsse:Security) and timestamp (wsu:Timestamp) labels I do have this code: from zeep import Client from zeep.wsse import UsernameToken from…
2
votes
0 answers

Building an XML file from an XSD using Python

can I build an XML file from XSD using Python? I found that xmlschema package expected to do this but failed to found a simple working example... For example, using the code below its not working for me: xs =…
Adi Ep
  • 509
  • 1
  • 5
  • 22
1
vote
0 answers

How to parse XML with Python xmlschema and preserve order of elements

I have to parse XML files that are in the root element a xs:choise. Some of the element types are hex encoded with little endian order, others are big endian order. Using a schema I can define different types for these. I am trying to use the…
PaulCC
  • 11
  • 1
1
vote
1 answer

Why does my python exe file give an winerror 3 (missing modules py2exe)

Update: I just tried to replicate my problem, and I found that there seems to be a problem when creating the exe file. py2exe says that 98 modules are missing and one of these are what is causing my winerror. I cannot, however, find the solution to…
1
vote
2 answers

Get list of description for each type in xml with Python

I have a xml file with the following format: <...> <...> Description 1 <...> <...>
Conquering
  • 39
  • 8
1
vote
0 answers

How is this notation called?

I used the xml / xml-schema example from here. When I decode the xml-string with the given schema, I get a nested dict as output: {'@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', '@orderid': '889923', '@xsi:noNamespaceSchemaLocation':…
testo
  • 1,052
  • 2
  • 8
  • 24
1
vote
2 answers

How to only get the tag that has text with it in lxml

I'm using lxml and I have a xml like this: 4 000413031 How can I only get the tag that has text like AUTO_ID and Meter,but not UploadFile Eu? I have tried: tree =…
William
  • 3,724
  • 9
  • 43
  • 76
1
vote
1 answer

How can I read multiple xsd strings into xmlschema

I have multiple XSD strings in my Python program, for example. xsd1 = '''
Edmund
  • 697
  • 6
  • 17
0
votes
1 answer

How to get line number from error iterator from XMLschema?

I'm fairly new to Python and coding in general so sorry if this is a very simple question. I'm working with the python packages XMLschema to validate some very large xml files. When I use the following code to get the error messages i only get the…
0
votes
1 answer

How to convert a pandas Dataframe to a xml tree format like pattern

I have a Dataframe ,you can have it by running : import pandas as pd from io import StringIO df = """ Name Type Format loan1 i type:num;width:10 loan2 a type:char;width:2 loan3 i …
William
  • 3,724
  • 9
  • 43
  • 76
0
votes
0 answers

How to validate the DataCite xml schema using Python and xmlschema?

I am trying to parse the latest DataCite xml schema version 4.4 (source files here). I found the xmlschema package for python which appears to be exactly what I want but I've been trying for 3 days now to get it to parse properly and can't seem to…
SSJenny90
  • 11
  • 1
0
votes
0 answers

Python lxml module removing whitespaces and some other things from some tags in XML Document even I don't want to remove

I am working with a program that modifies the content and structure of an XML document. My program has a set of class methods, each of which modifies a different XML tag. I have configured my configuration file to change the content of five…
JMS
  • 1
  • 1
0
votes
0 answers

Remove XML namespace attributes before converting to JSON

I'm converting an XML file to JSON. Namespace attributes in XML are also created in JSON file. How to remove that namespaces before converting XML to JSON? Below is my xml code This…
1
2