List of usage examples for org.jdom2 Parent getContent
<E extends Content> List<E> getContent(Filter<E> filter);
From source file:AIR.Common.xml.XmlElement.java
License:Open Source License
public XmlElement getPreviousSibling() { if (_element.getParent() == null) return null; Parent parent = _element.getParent(); int indexForThis = parent.indexOf(_element); if (indexForThis > 0) return new XmlElement(parent.getContent(--indexForThis)); return null;//from w w w.j a v a 2 s . c o m }
From source file:mil.tatrc.physiology.datamodel.doxygen.XSDToDoxygen.java
License:Open Source License
/** * Obtains any XML comments sibling content that immediately preceed this * element// w w w .j av a 2 s. co m * @param element * @return */ private String getComment(Element element) { Parent parent = element.getParent(); int i = parent.indexOf(element); StringBuffer comments = new StringBuffer(); // Search backward from this position for preceding comments for (int x = i - 1; x >= 0; x--) { Content c = parent.getContent(x); if (c.getCType() == Content.CType.Comment) { Comment comment = (Comment) c; String text = comment.getText().trim(); if (isValidComment(text)) { // This comment pertains to the preceding element if (text.startsWith("<<")) { break; } if (comments.length() > 0) { comments.insert(0, '\n'); } comments.insert(0, text); } } else if (c.getCType() == Content.CType.Element) { // Stop looking when we hit another element break; } } // Search forward from this position for inline commentx for (int x = i + 1; x < parent.getContentSize(); x++) { Content c = parent.getContent(x); if (c.getCType() == Content.CType.Comment) { Comment comment = (Comment) c; String text = comment.getText().trim(); if (isValidComment(text)) { // This comment pertains to the preceding element if (text.startsWith("<<")) { // Strip the "<<" text = text.substring(2); if (comments.length() > 0) { comments.insert(0, '\n'); } comments.insert(0, text); } else { break; } } } else if (c.getCType() == Content.CType.Element) { // Stop looking when we hit another element break; } } return comments.toString(); }