List of usage examples for org.dom4j Attribute getData
Object getData();
XML Schema
or Java Bean
bindings or will return the same value as Node#getText() . From source file:com.sammyun.util.XmlHelper.java
License:Open Source License
/** * ?XMLDto(?XML?)/*from w ww . j av a2s . co m*/ * * @param pStrXml ?XML * @param pXPath ("//paralist/row" paralistrowxPath) * @return outDto Dto */ public static final Dto parseXml2DtoBasedProperty(String pStrXml, String pXPath) { Dto outDto = new BaseDto(); String strTitle = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; Document document = null; try { if (pStrXml.indexOf("<?xml") < 0) pStrXml = strTitle + pStrXml; document = DocumentHelper.parseText(pStrXml); } catch (DocumentException e) { logger.error( "==??:==\nXML??XML DOM?!" + "\n?:"); e.printStackTrace(); } if (document != null) { // ?Xpath? Element elRoot = (Element) document.selectSingleNode(pXPath); // ??Dto for (Iterator it = elRoot.attributeIterator(); it.hasNext();) { Attribute attribute = (Attribute) it.next(); outDto.put(attribute.getName().toLowerCase(), attribute.getData()); } } return outDto; }
From source file:com.sammyun.util.XmlHelper.java
License:Open Source License
/** * XMLList(XML?)/*from w w w . ja v a 2 s . com*/ * * @param pStrXml ?XML? * @return list List */ public static final List parseXml2List(String pStrXml) { List lst = new ArrayList(); String strTitle = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; Document document = null; try { if (pStrXml.indexOf("<?xml") < 0) pStrXml = strTitle + pStrXml; document = DocumentHelper.parseText(pStrXml); } catch (DocumentException e) { logger.error( "==??:==\nXML??XML DOM?!" + "\n?:"); e.printStackTrace(); } if (document != null) { // ? Element elRoot = document.getRootElement(); // ?? Iterator elIt = elRoot.elementIterator(); while (elIt.hasNext()) { Element el = (Element) elIt.next(); Iterator attrIt = el.attributeIterator(); Dto dto = new BaseDto(); while (attrIt.hasNext()) { Attribute attribute = (Attribute) attrIt.next(); dto.put(attribute.getName().toLowerCase(), attribute.getData()); } lst.add(dto); } } return lst; }
From source file:org.dom4j.samples.bean.BeanDemo.java
License:Open Source License
protected void process(Document document) throws Exception { // find all of the windows List windows = document.selectNodes("//window"); for (Iterator iter = windows.iterator(); iter.hasNext();) { Element element = (Element) iter.next(); Object window = element.getData(); if (window instanceof Component) { Component component = (Component) window; component.setVisible(true);/* ww w . j av a2s .co m*/ } println("found element: " + element); println("found window: " + window); } println(""); println("Now lets find all the fonts..."); List fonts = document.selectNodes("//@font"); for (Iterator iter = fonts.iterator(); iter.hasNext();) { Attribute font = (Attribute) iter.next(); println("found font: " + font.getData()); } }
From source file:org.onecmdb.core.utils.xml.XmlParser.java
License:Open Source License
public void dumpElement(Element el, int level) { System.out.println(tab(level) + el.getName() + ":" + el.getData() + " {"); List attributes = el.attributes(); for (int i = 0; i < attributes.size(); i++) { Attribute a = (Attribute) attributes.get(i); System.out.println(tab(level) + " " + a.getName() + "=" + a.getData()); }/*w w w. ja v a2 s . co m*/ List els = el.elements(); for (int i = 0; i < els.size(); i++) { dumpElement((Element) els.get(i), level + 1); } System.out.println(tab(level) + "}"); }
From source file:org.orbeon.oxf.xforms.InstanceData.java
License:Open Source License
private static InstanceData createNewInstanceData(Node node) { final InstanceData instanceData; if (node instanceof Element) { final Element element = (Element) node; instanceData = InstanceData.createNewInstanceData(element.getData()); element.setData(instanceData);/* w w w .java 2 s . c o m*/ } else if (node instanceof Attribute) { final Attribute attribute = (Attribute) node; instanceData = InstanceData.createNewInstanceData(attribute.getData()); attribute.setData(instanceData); } else if (node instanceof Document) { // We can't store data on the Document object. Use root element instead. final Element element = ((Document) node).getRootElement(); instanceData = InstanceData.createNewInstanceData(element.getData()); element.setData(instanceData); } else { // No other node type is supported throw new OXFException("Cannot create InstanceData on node type: " + node.getNodeTypeName()); } return instanceData; }