Convert csv to xml with xsd

I am trying to find a reusable way to take a CSV file and create an XML file from it that matches the specified XSD. I actually did not find a reusable approach for this. I used Altova MapForce, which allows me to import a CSV file and XSD, do a mapping, than generate code from this, but the code needs to be restored whenever the XSD changes. Altova also produces a lot of code.

My ideal solution would be a set of Java classes into which I can provide a CSV file, XSD and get an XML file from it. I can’t find anything like it, although I’m thinking about the potential creation of something.

Ideas? Is there something here using XSLT based on this question?

Thanks.

+5
source share
5 answers

It seems like it would be easy to do, but it is not. XML Schema is a document validation language, not a document creation language. He does not tell you how to create a new document; it tells you if the document you made is valid. This is not the same thing: a long shot.

For example, it is trivial to create a complex type in an XML schema that consists of a sequence of optional options. An element foocan have either a child bar, or baz, or a child, bazor bat, then a child foo, baror bat. This creates a rule that can determine that both of these elements are valid:

<foo>
   <baz/>
   <baz/>
   <bar/>
</foo>

<foo>
   <foo>
      <bar/>
   </foo>
</foo>

, foo.

, - , , , . , . , . , , , .

, , - . , CSV XML , . XML, :

<item name="foo" type="string" size="10" allowNulls="true" .../>
<item name="bar" type="date" allowNulls="false" .../>

XML CSV, , XML. , XML .

, (, ), .

+7

, , :

  • CSV , FileHelphers; MyDataType, CSV, MyDataType

  • XML, [XmlIgnore], [XmlAttribute] .., MyDataType XML, XML-

  • , , XML ( XSD, ), MyDataType (from CSV) MyXmlDataType ( XML) - AutoMapper

, , "", ( ).

+2

"" ( CSV), () , () . XML- XSD.

, XML , / . , .

Could you post some CSV and XSD samples? This can help get a more focused response.

0
source

Microsoft Excel can export XML: http://office.microsoft.com/en-us/excel-help/export-xml-data-HP010206401.aspx

I'm having trouble creating an exported XSD format, but it's a great tool when you work it out.

0
source

All Articles