1

I have to create an XML document that would be based on an certain XML Schema Document. Since my data is a DataSet, I need to find the best way to start off.

I have couple of different ideas how to start:

  • manually create nodes, elements, attributes that would match XSD
  • transform DataSet into a class that would match the schema document and serialize it
  • something else?

Is this a right way to get a XML output from DataSet to match XSD schema?

Michael Piefel
  • 18,660
  • 9
  • 81
  • 112
mko
  • 6,638
  • 12
  • 67
  • 118
  • possible duplicate of [How to generate sample XML documents from their DTD or XSD?](http://stackoverflow.com/questions/17106/how-to-generate-sample-xml-documents-from-their-dtd-or-xsd) – Daniel Haley Feb 05 '13 at 08:56
  • Where exactly are you starting from? Would using an xsd2java tool be useful? – Donal Fellows Feb 05 '13 at 10:12
  • @DonalFellows Well I am trying to figure out what would be the best way to start... I have data as a DataSet in c#. – mko Feb 05 '13 at 10:38

1 Answers1

1

May be you should give XMLBeans a try... It's a diverse framework for playing around with compiled XSD schemas. Compiled in this context means, you create JAVA classes from your XSD-files.

Compilation example (as can be seen here) scomp -out purchaseorder.jar purchaseorder.xsd

With this jar in your classpath you could create new a priori valid instances of your schema with something like:

public PurchaseOrderDocument createPO() {
    PurchaseOrderDocument newPODoc = PurchaseOrderDocument.Factory.newInstance();
    PurchaseOrder newPO = newPODoc.addNewPurchaseOrder();
    Customer newCustomer = newPO.addNewCustomer();
    newCustomer.setName("Doris Kravitz");
    newCustomer.setAddress("Bellflower, CA");
    return newPODoc;
}

You can find the whole example at: XMLBeans Tutorial under the heading "Creating New XML Instances from Schema".

mle
  • 2,466
  • 1
  • 19
  • 25