问题
is there any library or way exist from which I can convert my xml records to yaml format ?
回答1:
This page has a pretty long discussion of the problem. It suggests a couple of Python libraries that could be used: Gnosis and generateDS.
回答2:
The difference between XML and YAML is significant enough to warrant a redesign of the schema you are using to store your data. You should write a script to parse your XML records and output YAML formatted data.
There are some methods out there to convert any generic XML into YAML, but the results are far less usable than a method designed specifically for your schema.
回答3:
I think you want to look at the YAXML draft spec, which describes how to represent YAML data structures in XML.
回答4:
It's not clear whether you are looking for a way to do this inside a script/program, or any Python method will do.
In the latter case, the yq
and xq
utilities can do this:
cat file.xml | xq . | yq -y .
They might also be reusable as libraries or at least reused code.
来源:https://stackoverflow.com/questions/2943862/is-there-anything-exist-to-convert-xml-yaml-directly