Codota Logo
org.dom4j
Code IndexAdd Codota to your IDE (free)

How to use org.dom4j

Best Java code snippets using org.dom4j (Showing top 20 results out of 3,501)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
StringBuilder s =
  • Codota Iconnew StringBuilder()
  • Codota Iconnew StringBuilder(32)
  • Codota IconString str;new StringBuilder(str)
  • Smart code suggestions by Codota
}
origin: Tencent/tinker

private void copyAttributes(Element srcNode, Element destNode) {
  for (Object attrObj : srcNode.attributes()) {
    final Attribute attr = (Attribute) attrObj;
    destNode.addAttribute(attr.getQName(), attr.getValue());
  }
}
origin: hibernate/hibernate-orm

private static void addOrModifyAttribute(Element parent, String name, String value) {
  final Attribute attribute = parent.attribute( name );
  if ( attribute == null ) {
    parent.addAttribute( name, value );
  }
  else {
    attribute.setValue( value );
  }
}
origin: igniterealtime/Openfire

public Route(Route route) {
  Element elementCopy = route.element.createCopy();
  docFactory.createDocument().add(elementCopy);
  this.element = elementCopy;
  // Copy cached JIDs (for performance reasons)
  this.toJID = route.toJID;
  this.fromJID = route.fromJID;
}
origin: spring-projects/spring-framework

private void validateOutput(String output, boolean selected) throws DocumentException {
  SAXReader reader = new SAXReader();
  Document document = reader.read(new StringReader(output));
  Element rootElement = document.getRootElement();
  assertEquals("select", rootElement.getName());
  assertEquals("country", rootElement.attribute("name").getValue());
  List children = rootElement.elements();
  assertEquals("Incorrect number of children", 4, children.size());
  Element e = (Element) rootElement.selectSingleNode("option[@value = 'UK']");
  Attribute selectedAttr = e.attribute("selected");
  if (selected) {
    assertTrue(selectedAttr != null && "selected".equals(selectedAttr.getValue()));
  }
  else {
    assertNull(selectedAttr);
  }
}
origin: spring-projects/spring-framework

@SuppressWarnings("rawtypes")
private void assertHtmlOutput(String output) throws Exception {
  SAXReader reader = new SAXReader();
  Document document = reader.read(new StringReader(output));
  List nodes = document.getRootElement().selectNodes("/html/body/table/tr");
  Element tr1 = (Element) nodes.get(0);
  assertRowElement(tr1, "1", "Whatsit", "12.99");
  Element tr2 = (Element) nodes.get(1);
  assertRowElement(tr2, "2", "Thingy", "13.99");
  Element tr3 = (Element) nodes.get(2);
  assertRowElement(tr3, "3", "Gizmo", "14.99");
  Element tr4 = (Element) nodes.get(3);
  assertRowElement(tr4, "4", "Cranktoggle", "11.99");
}
origin: igniterealtime/Openfire

public List<Element> getStanzaElements()
{
  return document.getRootElement().elements();
}
origin: igniterealtime/Openfire

  public Element asXMLElement() {
    Element option = DocumentHelper.createElement(QName.get("option", "jabber:x:data"));
    if (getLabel() != null) {
      option.addAttribute("label", getLabel());
    }
    if (getValue() != null) {
      option.addElement("value").addText(getValue());
    }
    return option;
  }
}
origin: igniterealtime/Openfire

public String asXML()
{
  return document.getRootElement().asXML();
}
origin: spring-projects/spring-framework

private void assertRowElement(Element elem, String id, String name, String price) {
  Element idElem = (Element) elem.elements().get(0);
  Element nameElem = (Element) elem.elements().get(1);
  Element priceElem = (Element) elem.elements().get(2);
  assertEquals("ID incorrect.", id, idElem.getText());
  assertEquals("Name incorrect.", name, nameElem.getText());
  assertEquals("Price incorrect.", price, priceElem.getText());
}
origin: igniterealtime/Openfire

protected static String createErrorBody(String type, String condition) {
  final Element body = DocumentHelper.createElement( QName.get( "body", "http://jabber.org/protocol/httpbind" ) );
  body.addAttribute("type", type);
  body.addAttribute("condition", condition);
  return body.asXML();
}
origin: igniterealtime/Openfire

@Override
public Element getSubsriptionErrorDetail() {
  return DocumentHelper.createElement(
      QName.get("closed-node", "http://jabber.org/protocol/pubsub#errors"));
}
origin: spring-projects/spring-framework

@Test
public void withSingleValueBooleanChecked() throws Exception {
  this.tag.setPath("jedi");
  int result = this.tag.doStartTag();
  assertEquals(Tag.SKIP_BODY, result);
  String output = getOutput();
  // wrap the output so it is valid XML
  output = "<doc>" + output + "</doc>";
  SAXReader reader = new SAXReader();
  Document document = reader.read(new StringReader(output));
  Element checkboxElement = (Element) document.getRootElement().elements().get(0);
  assertEquals("input", checkboxElement.getName());
  assertEquals("checkbox", checkboxElement.attribute("type").getValue());
  assertEquals("jedi", checkboxElement.attribute("name").getValue());
  assertEquals("checked", checkboxElement.attribute("checked").getValue());
  assertEquals("true", checkboxElement.attribute("value").getValue());
}
origin: igniterealtime/Openfire

@Override
public Element getSubsriptionErrorDetail() {
  return DocumentHelper.createElement(
      QName.get("not-in-roster-group", "http://jabber.org/protocol/pubsub#errors"));
}
origin: spring-projects/spring-framework

private void assertStringArray() throws JspException, DocumentException {
  int result = this.tag.doStartTag();
  assertEquals(Tag.SKIP_BODY, result);
  String output = getOutput();
  assertTrue(output.startsWith("<select "));
  assertTrue(output.endsWith("</select>"));
  SAXReader reader = new SAXReader();
  Document document = reader.read(new StringReader(output));
  Element rootElement = document.getRootElement();
  assertEquals("select", rootElement.getName());
  assertEquals("name", rootElement.attribute("name").getValue());
  List children = rootElement.elements();
  assertEquals("Incorrect number of children", 4, children.size());
  Element e = (Element) rootElement.selectSingleNode("option[text() = 'Rob']");
  assertEquals("Rob node not selected", "selected", e.attribute("selected").getValue());
}
origin: igniterealtime/Openfire

@Override
public Element getSubsriptionErrorDetail() {
  return DocumentHelper.createElement(QName.get("not-subscribed",
      "http://jabber.org/protocol/pubsub#errors"));
}
origin: spring-projects/spring-framework

@Test
public void collectionOfPetsAsString() throws Exception {
  this.tag.setPath("pets");
  this.tag.setValue("Spot");
  int result = this.tag.doStartTag();
  assertEquals(Tag.SKIP_BODY, result);
  String output = getOutput();
  // wrap the output so it is valid XML
  output = "<doc>" + output + "</doc>";
  SAXReader reader = new SAXReader();
  Document document = reader.read(new StringReader(output));
  Element checkboxElement = (Element) document.getRootElement().elements().get(0);
  assertEquals("input", checkboxElement.getName());
  assertEquals("checkbox", checkboxElement.attribute("type").getValue());
  assertEquals("pets", checkboxElement.attribute("name").getValue());
  assertEquals("checked", checkboxElement.attribute("checked").getValue());
}
origin: igniterealtime/Openfire

@Override
public Element getSubsriptionErrorDetail() {
  return DocumentHelper.createElement(QName.get("presence-subscription-required",
      "http://jabber.org/protocol/pubsub#errors"));
}
origin: spring-projects/spring-framework

@Test
public void collectionOfColoursSelected() throws Exception {
  this.tag.setPath("otherColours");
  this.tag.setValue("RED");
  int result = this.tag.doStartTag();
  assertEquals(Tag.SKIP_BODY, result);
  String output = getOutput();
  // wrap the output so it is valid XML
  output = "<doc>" + output + "</doc>";
  SAXReader reader = new SAXReader();
  Document document = reader.read(new StringReader(output));
  Element checkboxElement = (Element) document.getRootElement().elements().get(0);
  assertEquals("input", checkboxElement.getName());
  assertEquals("checkbox", checkboxElement.attribute("type").getValue());
  assertEquals("otherColours", checkboxElement.attribute("name").getValue());
  assertEquals("checked", checkboxElement.attribute("checked").getValue());
}
origin: spring-projects/spring-framework

@Test
public void collectionOfPetsAsStringNotSelected() throws Exception {
  this.tag.setPath("pets");
  this.tag.setValue("Santa's Little Helper");
  int result = this.tag.doStartTag();
  assertEquals(Tag.SKIP_BODY, result);
  String output = getOutput();
  // wrap the output so it is valid XML
  output = "<doc>" + output + "</doc>";
  SAXReader reader = new SAXReader();
  Document document = reader.read(new StringReader(output));
  Element checkboxElement = (Element) document.getRootElement().elements().get(0);
  assertEquals("input", checkboxElement.getName());
  assertEquals("checkbox", checkboxElement.attribute("type").getValue());
  assertEquals("pets", checkboxElement.attribute("name").getValue());
  assertNull(checkboxElement.attribute("checked"));
}
origin: spring-projects/spring-framework

@Test
public void collectionOfColoursNotSelected() throws Exception {
  this.tag.setPath("otherColours");
  this.tag.setValue("PURPLE");
  int result = this.tag.doStartTag();
  assertEquals(Tag.SKIP_BODY, result);
  String output = getOutput();
  // wrap the output so it is valid XML
  output = "<doc>" + output + "</doc>";
  SAXReader reader = new SAXReader();
  Document document = reader.read(new StringReader(output));
  Element checkboxElement = (Element) document.getRootElement().elements().get(0);
  assertEquals("input", checkboxElement.getName());
  assertEquals("checkbox", checkboxElement.attribute("type").getValue());
  assertEquals("otherColours", checkboxElement.attribute("name").getValue());
  assertNull(checkboxElement.attribute("checked"));
}
org.dom4j

Most used classes

  • Element
  • Document
  • SAXReader
  • XMLWriter
    XMLWriter takes a DOM4J tree and formats it to a stream as XML. It can also take SAX events too so c
  • OutputFormat
    OutputFormat represents the format configuration used by XMLWriterand its base classes to format the
  • Attribute,
  • Node,
  • DocumentException,
  • DocumentFactory,
  • QName,
  • Namespace,
  • DOMReader,
  • Branch,
  • XPath,
  • DefaultElement,
  • DocumentSource,
  • DOMElement,
  • DocumentType,
  • ProcessingInstruction
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now