Esempio n. 1
0
 @Override
 public Element getXml() {
   DocumentFactory f = DocumentFactory.getInstance();
   Element toRet = f.createElement("gene");
   toRet.addAttribute("name", this.getName());
   toRet.addAttribute("expressiveness", this.getExpressiveness().toString());
   return toRet;
 }
Esempio n. 2
0
 public static void dom4j() throws IOException {
   // DOM4J allows construction of "invalid" (?) XML document
   org.dom4j.DocumentFactory fact = new org.dom4j.DocumentFactory();
   org.dom4j.Element root = fact.createElement("todo:todo");
   org.dom4j.Document doc = fact.createDocument(root);
   System.out.println("DOM4J: ");
   System.out.println(doc.asXML());
 }
Esempio n. 3
0
  public static void dom4jWithURI() throws IOException {
    org.dom4j.DocumentFactory fact = new org.dom4j.DocumentFactory();
    org.dom4j.Element root = fact.createElement("todo:todo" /*, "http://www.example.com" */);

    // Namespace decl should be declared explicitly
    root.addNamespace("todo", "http://www.example.com");
    org.dom4j.Document doc = fact.createDocument(root);
    System.out.println("DOM4J: ");
    System.out.println(doc.asXML());
  }
Esempio n. 4
0
 /**
  * Writes this configuration to an XML element
  *
  * @param df The document factory with which to create the element
  * @return The XML element representing this configuration
  */
 public Element toXML(org.dom4j.DocumentFactory df) {
   Element ret = df.createElement(theName);
   if (theValue != null) ret.setText(theValue);
   java.util.HashMap<String, int[]> attrs = new java.util.HashMap<String, int[]>();
   for (MutableConfig sub : theSubConfigs) {
     int[] count = attrs.get(sub.theName);
     if (count == null) {
       count = new int[1];
       attrs.put(sub.theName, count);
     }
     count[0]++;
   }
   for (MutableConfig sub : theSubConfigs) {
     if (attrs.get(sub.theName)[0] == 1
         && sub.theSubConfigs.length == 0
         && sub.theValue != null
         && sub.theValue.indexOf('\n') < 0) ret.addAttribute(sub.theName, sub.theValue);
     else ret.add(sub.toXML(df));
   }
   return ret;
 }
Esempio n. 5
0
  @Override
  // Implementation methods
  // -------------------------------------------------------------------------
  protected Document parseDocument() throws DocumentException, IOException, XmlPullParserException {
    DocumentFactory df = getDocumentFactory();
    Document document = df.createDocument();
    Element parent = null;
    XmlPullParser pp = getXPPParser();
    pp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);

    while (true) {
      int type = pp.nextToken();

      switch (type) {
        case XmlPullParser.PROCESSING_INSTRUCTION:
          {
            String text = pp.getText();
            int loc = text.indexOf(' ');

            if (loc >= 0) {
              String target = text.substring(0, loc);
              String txt = text.substring(loc + 1);
              document.addProcessingInstruction(target, txt);
            } else {
              document.addProcessingInstruction(text, "");
            }

            break;
          }

        case XmlPullParser.COMMENT:
          {
            if (parent != null) {
              parent.addComment(pp.getText());
            } else {
              document.addComment(pp.getText());
            }

            break;
          }

        case XmlPullParser.CDSECT:
          {
            if (parent != null) {
              parent.addCDATA(pp.getText());
            } else {
              String msg = "Cannot have text content outside of the " + "root document";
              throw new DocumentException(msg);
            }

            break;
          }

        case XmlPullParser.END_DOCUMENT:
          return document;

        case XmlPullParser.START_TAG:
          {
            QName qname =
                (pp.getPrefix() == null)
                    ? df.createQName(pp.getName(), pp.getNamespace())
                    : df.createQName(pp.getName(), pp.getPrefix(), pp.getNamespace());
            Element newElement = df.createElement(qname);
            int nsStart = pp.getNamespaceCount(pp.getDepth() - 1);
            int nsEnd = pp.getNamespaceCount(pp.getDepth());

            for (int i = nsStart; i < nsEnd; i++) {
              if (pp.getNamespacePrefix(i) != null) {
                newElement.addNamespace(pp.getNamespacePrefix(i), pp.getNamespaceUri(i));
              }
            }

            for (int i = 0; i < pp.getAttributeCount(); i++) {
              QName qa =
                  (pp.getAttributePrefix(i) == null)
                      ? df.createQName(pp.getAttributeName(i))
                      : df.createQName(
                          pp.getAttributeName(i),
                          pp.getAttributePrefix(i),
                          pp.getAttributeNamespace(i));
              newElement.addAttribute(qa, pp.getAttributeValue(i));
            }

            if (parent != null) {
              parent.add(newElement);
            } else {
              document.add(newElement);
            }

            parent = newElement;

            break;
          }

        case XmlPullParser.END_TAG:
          {
            if (parent != null) {
              parent = parent.getParent();
            }

            break;
          }

        case XmlPullParser.ENTITY_REF:
        case XmlPullParser.TEXT:
          {
            String text = pp.getText();

            if (parent != null) {
              parent.addText(text);
            } else {
              String msg = "Cannot have text content outside of the " + "root document";
              throw new DocumentException(msg);
            }

            break;
          }

        default:
          break;
      }
    }
  }
 public Element createElement(String name) {
   return proxy.createElement(name);
 }
 public Element createElement(QName qname) {
   return proxy.createElement(qname);
 }
Esempio n. 8
0
 @Override
 public void resolutionDiagnostics(Branch context, DocumentFactory fac) {
   Element e = fac.createElement("ForEachShim");
   context.add(e);
   parent.resolutionDiagnostics(e, fac);
 }