使用python解析XSD文件 [英] Parse an XSD file using python

查看:82
本文介绍了使用python解析XSD文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从给定的XML模式生成XML文件.我已经能够使用python中的pyxb库做到这一点.但是问题在于,由于XSD越来越庞大,因此无法对每个标签和evey标签进行手动编码.是否有任何python库可以从给定的XSD文件创建数据结构,该文件可以通过

I am trying to generate an XML file from a given XML schema. I have been able to do it with pyxb library in python. But the problem is as the XSD gets huge it is impossible to manually encode each and evey tag. Is there any python library which creates a data structure from a given XSD file which can be iterated through

推荐答案

您可以从XSD文件生成XML文件:

You can generate XML file from XSD file:

import requests

with open('file.xsd', 'r') as f:
    data = f.read()
r = requests.post('https://www.liquid-technologies.com/api/Converter', json={"Filename": "schema.xsd", "Type": "xsd", "Data": data, "TargetType": "xml", "Arguments": {"elementName": "Root", "elementNamespace": "", "addAnyAttributes": False, "addAnyElements": False, "forceOptionItemsToDepthOf": "4", "forceXsiNamespaceDelaration": False, "maxDepthToCreateOptionalItems": "7", "indent": "2", "indentChar": " ", "indentAttributes": False, "seed": "9722"}})
with open('file.xml', 'w') as f:
    f.write(r.json()['Files'][0]['Data'])

这篇关于使用python解析XSD文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆