XSD Schemas for Extensions

All of the extension object model are generated using JAXB from the following schema. Some of them are official schema (which are usually higher quality) provided by the specs, some of them I created myself (which are usually very simplistic).

Adding support for your favorite extension

Since the object model are generated by JAXB, they are not in the builder style as the core model. You might want the extension elements to be mapped to your own object model. There also might be some extension elements that Yarfraw does not yet support. You should consider adding support for these extension elements instead of working with the DOM element object directly.

To do that, all you need to do is to write two mapping methods: one method to convert a custom object into a list of DOM elements; one method to convert a list of DOM elements into the same custom object. Yarfraw does not impose any restrctions on the signature of these mapping methods, but in general, they should look like:

    public static YourExtension extractYourExtension(List<Element> otherElements) throws YarfrawException;
    public static List<Element> toYourExtensionElements(YourExtension extensionObject) throws YarfrawException;

If you have written support methods for an extension that Yarfraw does not yet support, or you feel that your object model is better than the one that Yarfraw currently uses, please send me a note and I will be more than happy to replace Yarfraw's current implementation with yours. As mentioned above, all the extension object models are generated by JAXB using some xsd schema files. If the extension you would like to add already has a schema file, you can use the JAXB binding tools to convert it to an object model and then implement the extension methods as followed:

  public static List<Element> toYourExtensionElements(YourExtension extensionObject) throws YarfrawException{
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    List<Element> ret = new ArrayList<Element>();
    try {
      Document doc = dbf.newDocumentBuilder().newDocument();
      Marshaller m = getContext("your jaxb context").createMarshaller();
      //setup other marshaller properties, such as preferred prefix mapping
      m.marshal(extensionObject, doc);
      Element e = doc.getDocumentElement();
      NodeList list =  e.getChildNodes();
      for(int i =0; i< list.getLength(); i++){
        Node n = list.item(i);
        if (n instanceof Element) {
          Element element = (Element) n;
        }else {
          LOG.error("Ignore unexpected node "+n.getNodeName()+", this should not happen");
    catch (ParserConfigurationException e) {
      throw new YarfrawException("Parserconfig exception", e);
    catch (JAXBException e) {
      throw new YarfrawException("JAXB exception", e);
    return ret;

  public static YourExtension extractYourExtension(List<Element> otherElements) throws YarfrawException{
    YourExtension ret = new YourExtension();
    try {
      if(otherElements != null){
        Iterator<Element> it = otherElements.iterator();
        Unmarshaller u = getContext("your jaxb context").createUnmarshaller();
          Element e = it.next();
          if(e == null){
          QName name = new QName(e.getNamespaceURI(), e.getLocalName());
          if(XMLUtils.same(name, new QName("the qname of the extension element"))){
                //add the element to the extension object
          }else if(...){
                //do the same thing for all supported elements
    catch (JAXBException e) {
      throw new YarfrawException("unable to unmarshal element", e);

    return ret;

If for whatever reason, you do not want to use JAXB, you can use any other XML binding framework, or even do the object binding manually. The reason that I am using JAXB here is because it does most of the work for me so I can add things really quickly.

For more details, I encourage to take a look at the Javadoc . Also check out the FAQ section for more insights about this API.