List of usage examples for org.dom4j Attribute getValue
String getValue();
From source file:eu.planets_project.pp.plato.util.XMLCompare.java
License:Open Source License
private boolean compareTrees(Element node1, Document doc2, boolean ignoreEmptyNodes, boolean ignoreEmptyAttributes) { boolean isValid = true; Element root2 = doc2.getRootElement(); String path = node1.getUniquePath(); Element elementDoc2 = (Element) doc2.selectSingleNode(path); // the node doesn't exist in doc2 if (elementDoc2 == null && node1.elements().size() == 0 && "".equals(node1.getTextTrim())) { if (ignoreEmptyNodes == false) { errorMessages/*from ww w . j av a2 s .c o m*/ .append("The following empty node doesnt exist in xml file #2: " + node1.getUniquePath()) .append(System.getProperty("line.separator")); isValid = false; } } else if (elementDoc2 == null && (node1.elements().size() > 0 || !"".equals(node1.getTextTrim()))) { errorMessages.append("The following node (which is not empty) doesn't exist in xml file #2: " + node1.getUniquePath() + System.getProperty("line.separator")); errorMessages.append("File #1: " + node1.getTextTrim() + System.getProperty("line.separator")); errorMessages .append("File #2: " + ((elementDoc2 == null) ? "<not existent>" : elementDoc2.getTextTrim()) + System.getProperty("line.separator")); isValid = false; } else if (elementDoc2 == null || !elementDoc2.getTextTrim().equals(node1.getTextTrim())) { errorMessages.append("Text of following nodes not equal in both xmls: " + node1.getUniquePath() + System.getProperty("line.separator")); errorMessages.append("File #1: " + node1.getTextTrim() + System.getProperty("line.separator")); errorMessages .append("File #2: " + ((elementDoc2 == null) ? "<not existent>" : elementDoc2.getTextTrim()) + System.getProperty("line.separator")); isValid = false; } // // compare attributes // List<Attribute> attributes = node1.attributes(); for (Attribute a : attributes) { String attributePath = a.getUniquePath(); org.dom4j.Node node = root2.selectSingleNode(attributePath); if (node == null && "".equals(a.getValue().trim())) { // document 1 has an empty attribute (sting length = 0) which // does not exist in document 2 if (ignoreEmptyAttributes == false) { errorMessages.append( "Attribute " + a.getName() + " doesn't exist in xml file #2, node " + a.getUniquePath()) .append(System.getProperty("line.separator")); isValid = false; } continue; } if (node == null || !a.getValue().equals(node.getText())) { errorMessages.append("Value of following attribute not equal in both xmls: " + a.getUniquePath() + System.getProperty("line.separator")); errorMessages.append("File #1: " + a.getValue() + System.getProperty("line.separator")); errorMessages.append("File #2: " + ((node != null) ? node.getText() : "<not existent>") + System.getProperty("line.separator")); isValid = false; } } List<Element> elements = node1.elements(); for (Element e : elements) { if (!compareTrees(e, doc2, ignoreEmptyNodes, ignoreEmptyAttributes)) { isValid = false; } } return isValid; }
From source file:fr.gouv.culture.vitam.utils.XmlDom.java
License:Open Source License
public final static void removeEmptyAttribute(Attribute attrib) { if (attrib.getValue().length() == 0) { attrib.detach();//from w w w . j a va2 s . com } }
From source file:fr.gouv.vitam.xml.XmlDom4jTools.java
License:Open Source License
public final static void removeEmptyElement(Element root) { // look first at attribute if (root.attributeCount() > 0) { @SuppressWarnings("unchecked") Iterator<Attribute> attribs = root.attributeIterator(); List<Attribute> toremove = new ArrayList<>(); while (attribs.hasNext()) { Attribute attribute = (Attribute) attribs.next(); if (attribute.getValue().length() == 0) { toremove.add(attribute); }//from w w w .j a v a2s. com //removeEmptyAttribute(attribute); } for (Attribute attribute : toremove) { root.remove(attribute); } toremove.clear(); } @SuppressWarnings("unchecked") Iterator<Element> elements = root.elementIterator(); List<Element> toremove = new ArrayList<>(); while (elements.hasNext()) { Element elt = (Element) elements.next(); // look at its descendant removeEmptyElement(elt); if (elt.attributeCount() > 0) { continue; } if (elt.hasContent()) { continue; } toremove.add(elt); //elt.detach(); } for (Element element : toremove) { root.remove(element); } toremove.clear(); }
From source file:fr.isima.ponge.wsprotocol.gefeditor.editparts.propertysources.OperationPropertySource.java
License:Open Source License
/** * Trys to get the messages names from a WSDL document. * //from w w w . j a v a2s . c o m * @return The list of the messages names or <code>Collections.EMPTY_LIST</code>. */ protected List getWSDLMessagesNames() { // No WSDL if (wsdlLocation == null || "".equals(wsdlLocation)) //$NON-NLS-1$ { return Collections.EMPTY_LIST; } // Cached parsings if (cachedParsings.containsKey(wsdlLocation)) { return (List) cachedParsings.get(wsdlLocation); } // Parse the WSDL cleanProblemMarkers(WSDL_PROBLEM_MARKER_ID); List names = new ArrayList(); try { SAXReader reader = new SAXReader(); Document document = reader.read(new URL(wsdlLocation)); Iterator nodesIt = document.selectNodes("//*[local-name()='message']/@name").iterator(); while (nodesIt.hasNext()) { Attribute attr = (Attribute) nodesIt.next(); names.add(attr.getValue()); } Collections.sort(names); } catch (MalformedURLException e) { reportWSDLProblem(); } catch (DocumentException e) { reportWSDLProblem(); } cachedParsings.put(wsdlLocation, (names.size() > 0) ? names : Collections.EMPTY_LIST); return (names.size() > 0) ? names : Collections.EMPTY_LIST; }
From source file:fr.mael.microrss.xml.opml.OPMLReader.java
License:Open Source License
private String getAttribute(String attributeName, Element element) { for (Iterator i = element.attributeIterator(); i.hasNext();) { Attribute attribute = (Attribute) i.next(); if (attributeName.equals(attribute.getName())) { return attribute.getValue(); }//from www. j a v a 2s .c om } return null; }
From source file:galign.helpers.tmx.TmxHeader.java
License:Apache License
private void init(Element p_element) { Attribute attr; List nodes;/*from w w w .ja va 2 s. co m*/ Date date; // mandatory m_creationtoolversion = p_element.attributeValue(CREATIONTOOLVERSION); m_creationtool = p_element.attributeValue(CREATIONTOOL); m_segtype = p_element.attributeValue(SEGTYPE); m_o_tmf = p_element.attributeValue(O_TMF); m_adminlang = p_element.attributeValue(ADMINLANG); m_srclang = p_element.attributeValue(SRCLANG); m_datatype = p_element.attributeValue(DATATYPE); // optional m_o_encoding = p_element.attributeValue(O_ENCODING); m_creationid = p_element.attributeValue(CREATIONID); m_changeid = p_element.attributeValue(CHANGEID); attr = p_element.attribute(CREATIONDATE); if (attr == null) { date = null; } else { date = UTC.parseNoSeparators(attr.getValue()); if (date == null) { date = UTC.parse(attr.getValue()); } } m_creationdate = date; attr = p_element.attribute(CHANGEDATE); if (attr == null) { date = null; } else { date = UTC.parseNoSeparators(attr.getValue()); if (date == null) { date = UTC.parse(attr.getValue()); } } m_changedate = date; // elements for (Iterator i = p_element.elementIterator("note"); i.hasNext();) { Element node = (Element) i.next(); m_notes.add(new Note(node)); } for (Iterator i = p_element.elementIterator("prop"); i.hasNext();) { Element node = (Element) i.next(); m_props.add(new Prop(node)); } // TODO: UDE }
From source file:gov.nih.nci.caarray.util.owlparser.AbstractOntologyOwlParser.java
License:BSD License
private String getIdentifier(Element e) { Attribute id = e.attribute(getIdAttributeName()); if (id != null) { return id.getValue(); }/* w w w . j a v a 2 s.co m*/ Attribute about = e.attribute(getAboutAttributeName()); if (about != null) { return StringUtils.substringAfter(about.getValue(), FRAGMENT_SEPARATOR); } Attribute resource = e.attribute(getResourceAttributeName()); if (resource != null) { return StringUtils.substringAfter(resource.getValue(), FRAGMENT_SEPARATOR); } return null; }
From source file:hello.SampleSimpleApplication.java
License:Apache License
private void changeImgUrl(Element autoTileElement) { List<Element> selectNodes = autoTileElement.selectNodes(".//img"); for (Element bagroundImage : selectNodes) { Attribute srcImg = bagroundImage.attribute("src"); if (!srcImg.getValue().contains(domain)) srcImg.setValue(domain + "/" + srcImg.getValue()); }//from w ww.j a v a 2s . com // Element bagroundImage = (Element) autoTileElement.selectSingleNode("img[1]"); }
From source file:hello.W2j.java
License:Apache License
private void readAutoIndexList(String autoTileHref, String autoName, String manufacturer) { autoTileAllIndexNr = 0;// w w w . j ava2 s . com initAutoData(); readNextAutoIndexList(autoTileHref); while (nextAutoTileElement != null) { getNextTrueSibling(); if (nextAutoTileElement == null) { break; } Attribute hrefAttribute = (Attribute) nextAutoTileElement.selectSingleNode("a/@href"); String hrefAutoTileNext = hrefAttribute.getValue(); readNextAutoIndexList(hrefAutoTileNext); } try { // buildBookmark(autoDocument); autoName = autoName.replaceAll(" ", "_"); String htmlOutFileName = getHtmlOutFileName(autoName, manufacturer); // saveHtml(autoDocument, htmlOutFileName); // savePdf(htmlOutFileName, htmlOutFileName+".pdf"); writeToJsonDbFile(autoData, htmlOutFileName + ".json"); } catch (Exception e) { e.printStackTrace(); } }
From source file:it.intecs.pisa.openCatalogue.solr.ingester.Ingester.java
private static void generateMap2(org.dom4j.Element el, Map map) { String value = el.getTextTrim(); String currentPath = getXPath(el); Iterator a = null;/*w ww . ja va 2s .c o m*/ Iterator i = el.elementIterator(); a = el.attributeIterator(); while (a.hasNext()) { org.dom4j.Attribute attr = (org.dom4j.Attribute) a.next(); String aval = attr.getValue(); String apath = currentPath + "_" + attr.getName(); //System.out.println("PATH:" + apath + " --- " + aval); map.put(apath, aval); } if (!i.hasNext() && value != null) { // System.out.println("PATH:" + currentPath); map.put(currentPath, value); } else { while (i.hasNext()) { generateMap2((org.dom4j.Element) i.next(), map); } } }