-
Notifications
You must be signed in to change notification settings - Fork 61
Open
Description
I have a need to convert XML to Avro and i am exploring this tool to achieve the same.
Xml Sample
<employee id="100">
<department id="1000">HR</department>
</employee>
XSD
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element name="department">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:short" name="id"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:byte" name="id"/>
</xs:complexType>
</xs:element>
</xs:schema>
Code for the conversion
public static void main(String[] args) {
Schema schema = Converter.createSchema(new File("employee.xsd"));
GenericData.Record record = Converter.createDatum(schema, new File("employee.xml"));
System.out.println(record.get("department"));
System.out.println(record.get("employee"));
}
Output
{"id": 1000}
null
Questions
- How do i get the id attribute from the employee tag?
- How do i get the text from the department tag? The output prints only the attriabutes.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels