开发者

Is there a way to create XML dat according to an XSD in Perl?

开发者 https://www.devze.com 2023-01-20 12:32 出处:网络
I have a CSV file, and a XSD from which I need to create an XML file which conforms to the XSD Schema. Is there a 开发者_如何学运维way to create an XML according to an XSD? Doing it manually seems unr

I have a CSV file, and a XSD from which I need to create an XML file which conforms to the XSD Schema. Is there a 开发者_如何学运维way to create an XML according to an XSD? Doing it manually seems unreasonable.


XML::Compile can do that for you. XML::Compile::Schema has the bits probably most relevant to your problem.


If you're looking for some magic csv2xsd script, you're going to be disappointed. The problem is that CSV is a simple flat structure, while the XML is a hierarchical structure that is further constrained by the XSD. You will have to manually determine which fields of the CSV pertain to which elements in the XSD, and figure out how to deal with minimums, maximums, required elements, etc.

Using a tool that attempts to interpret, compile, or otherwise 'automatically' deal with a schema is going to end up requiring the same level of effort (at least) to perform the mapping, not including the additional learning curve and complexity you'd be introducing. For a one-time task, this won't be worth your while.

Honestly, the simplest thing is to understand the schema and generate your XML accordingly. If you need help with reading XSD, there are many tools that can help you visualize it. Another option is to generate sample XML from the schema as a model.

0

精彩评论

暂无评论...
验证码 换一张
取 消