user619882
user619882

Reputation: 349

clojure generate xml and xpaths from xsd

In Clojure is there a simple way to generate some sample xml based on an xsd? And how would you pull out the xpaths from the xml? (This seems the kind of problem that Clojure is good at.)

For example - turn this:

 <xsd:complexType name="USAddress">
  <xsd:sequence>
   <xsd:element name="name"   type="xsd:string"/>
   <xsd:element name="street" type="xsd:string"/>
   <xsd:element name="city"   type="xsd:string"/>
   <xsd:element name="state"  type="xsd:string"/>
   <xsd:element name="zip"    type="xsd:integer"/>
  </xsd:sequence>
  <xsd:attribute name="country" type="xsd:NMTOKEN" fixed="US"/>
 </xsd:complexType>
</xsd:schema>

To this:

<?xml version="1.0" encoding="utf-8"?>
<PurchaseOrder OrderDate="2012-12-13">
  <ShipTo country="US">
    <name>str1234</name>
    <street>str1234</street>
    <city>str1234</city>
    <state>str1234</state>
    <zip>1234</zip>
  </ShipTo>
  <BillTo country="US">
    <name>str1234</name>
    <street>str1234</street>
    <city>str1234</city>
    <state>str1234</state>
    <zip>1234</zip>
  </BillTo>
</PurchaseOrder>

Upvotes: 1

Views: 845

Answers (1)

Chiron
Chiron

Reputation: 20245

Clojure provides a really code library for XML manipulation (clojure.data.xml). And for XPath, then I think it is worth to have a look at: clj-xpath.
With those libraries, your case should be easier.

Upvotes: 2

Related Questions