List of usage examples for org.w3c.dom Element getAttribute
public String getAttribute(String name);
From source file:Main.java
/** * equivalent to the XPath expression './/tagName[@attrName='attrValue']' *//* ww w . j av a 2 s.c o m*/ public static Element getElementByAttributeValue(Node start, String tagName, String attrName, String attrValue) { NodeList nl = ((Element) start).getElementsByTagName(tagName); int l = nl.getLength(); if (l == 0) { return null; } Element e = null; String compareValue = null; for (int i = 0; i < l; i++) { e = (Element) nl.item(i); if (e.getNodeType() == Node.ELEMENT_NODE) { compareValue = e.getAttribute(attrName); if (compareValue.equals(attrValue)) { return e; } } } return null; }
From source file:biz.webgate.tools.urlfetcher.URLFetcher.java
public static void checkDescription(PageAnalyse analyse, NodeList ndlMet) { if ("".equals(analyse.getDescription())) { for (int nCounter = 0; nCounter < ndlMet.getLength(); nCounter++) { Element elCurrent = (Element) ndlMet.item(nCounter); if ("description".equalsIgnoreCase(elCurrent.getAttribute("name")) && elCurrent.hasAttribute("content")) { analyse.setDescription(elCurrent.getAttribute("content")); break; }/*from w w w .j av a 2s . c o m*/ } } }
From source file:Main.java
/** * equivalent to the XPath expression './/tagName[@attrName='attrValue']' *///from w w w . j av a 2 s . c o m public static Element getElementByAttributeValue(final Node start, final String tagName, final String attrName, final String attrValue) { NodeList nl = ((Element) start).getElementsByTagName(tagName); int l = nl.getLength(); if (l == 0) { return null; } Element e = null; String compareValue = null; for (int i = 0; i < l; i++) { e = (Element) nl.item(i); if (e.getNodeType() == Node.ELEMENT_NODE) { compareValue = e.getAttribute(attrName); if (compareValue.equals(attrValue)) { return e; } } } return null; }
From source file:Main.java
public static ArrayList<String> getNodeListAttValAsStringCol(final String xPath, final Node node, final String attrName) throws Exception { ArrayList<String> retV = new ArrayList<String>(); NodeList nl = getNodesListXpathNode(xPath, node); int l = nl.getLength(); Element e = null; String val = ""; for (int i = 0; i < l; i++) { e = (Element) nl.item(i); if (e.getNodeType() == Node.ELEMENT_NODE) { val = e.getAttribute(attrName); if (val != null && val.length() > 0) { retV.add(val); }/*from www . j av a 2 s .co m*/ } } return retV; }
From source file:Main.java
public static ArrayList<String> getNodeListAttValAsStringCol(String Xpath, Node node, String attrName) throws Exception { ArrayList<String> retV = new ArrayList<String>(); NodeList nl = getNodesListXpathNode(Xpath, node); int l = nl.getLength(); Element e = null; String val = ""; for (int i = 0; i < l; i++) { e = (Element) nl.item(i); if (e.getNodeType() == Node.ELEMENT_NODE) { val = e.getAttribute(attrName); if (val != null && val.length() > 0) { //log.info("getNodeListAttValAsStringCol val = "+val +" attname = "+attrName); /*try {//from w w w.j ava 2 s. c om log.info(convertToStringLeaveCDATA(e)); }catch(Exception E) { E.printStackTrace(); }*/ retV.add(val); } } } return retV; }
From source file:com.seovic.validation.config.ValidationBeanDefinitionParser.java
private static BeanDefinition parseErrorMessageAction(Element message, ParserContext parserContext) { String messageId = message.getAttribute("id"); String[] providers = message.getAttribute("providers").split(","); String typeName = ErrorMessageAction.class.getName(); ConstructorArgumentValues ctorArgs = new ConstructorArgumentValues(); ctorArgs.addGenericArgumentValue(messageId); ctorArgs.addGenericArgumentValue(providers); String when = message.getAttribute("when"); MutablePropertyValues properties = new MutablePropertyValues(); if (StringUtils.hasText(when)) { properties.addPropertyValue("when", when); }// w w w .j a v a 2 s. c o m AbstractBeanDefinition action; try { action = BeanDefinitionReaderUtils.createBeanDefinition(null, typeName, parserContext.getReaderContext().getBeanClassLoader()); } catch (ClassNotFoundException e) { throw new BeanCreationException("Error occured during creation of bean definition", e); } action.setConstructorArgumentValues(ctorArgs); action.setPropertyValues(properties); return action; }
From source file:org.shareok.data.documentProcessor.FileHandlerFactory.java
/** * * @param fileExtension/* ww w . jav a 2s . c o m*/ * @return */ public static FileHandler getFileHandlerByFileExtension(String fileExtension) { FileHandler fh = null; String beanName = ""; try { String fileTypePath = DocumentProcessorUtil.getFilePathFromResources("filetypes.xml"); Document fileTypeDoc = loadXMLFromString(fileTypePath); fileTypeDoc.getDocumentElement().normalize(); Element docEle = fileTypeDoc.getDocumentElement(); NodeList nl = docEle.getChildNodes(); if (nl != null && nl.getLength() > 0) { for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i).getNodeType() == Node.ELEMENT_NODE) { Element el = (Element) nl.item(i); String nodeVal = el.getTextContent(); if (nodeVal.equals(fileExtension)) { beanName = el.getAttribute("bean"); break; } } } } ApplicationContext context = new ClassPathXmlApplicationContext("documentProcessorContext.xml"); fh = (FileHandler) context.getBean(beanName); } catch (Exception ex) { Logger.getLogger(DocumentProcessorUtil.class.getName()).log(Level.SEVERE, null, ex); } return fh; }
From source file:Main.java
/** * Converts XML {@code <property name=""></property>} tags to Properties * object./*from www .j av a 2s . co m*/ * * @see java.util.XmlUtils.importProperties() * * @param entries * List of property nodes in the DOM */ public static Properties importProperties(NodeList entries) { Properties props = new Properties(); int numEntries = entries.getLength(); for (int i = 0; i < numEntries; i++) { Element entry = (Element) entries.item(i); if (entry.hasAttribute("name")) { Node n = entry.getFirstChild(); String val = (n == null) ? "" : n.getNodeValue(); props.setProperty(entry.getAttribute("name"), val); } } return props; }
From source file:com.microsoft.tfs.core.clients.sharepoint.WSSNode.java
/** * Create a strongly typed WssNode from data passed back from the WSS Web * Service./* ww w. ja v a2 s .c om*/ * * @return WssDocument or WssFolder representing point on node. */ public static WSSNode buildWSSNode(final Element element) { final String wssObjType = WSSUtils.decodeWSSString(element.getAttribute("ows_FSObjType")); //$NON-NLS-1$ if (WSSObjectType.FILE.equals(wssObjType)) { return new WSSDocument(element); } if (WSSObjectType.FOLDER.equals(wssObjType)) { return new WSSFolder(element); } return new WSSNode(element); }
From source file:com.codebutler.farebot.mifare.Card.java
public static Card fromXml(String xml) throws Exception { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = builder.parse(new InputSource(new StringReader(xml))); Element rootElement = doc.getDocumentElement(); CardType type = CardType.class.getEnumConstants()[Integer.parseInt(rootElement.getAttribute("type"))]; byte[] id = Utils.hexStringToByteArray(rootElement.getAttribute("id")); Date scannedAt = rootElement.hasAttribute("scanned_at") ? new Date(Long.valueOf(rootElement.getAttribute("scanned_at"))) : new Date(0); switch (type) { case MifareDesfire: return DesfireCard.fromXml(id, scannedAt, rootElement); case CEPAS:/* w ww. java 2s . co m*/ return CEPASCard.fromXML(id, scannedAt, rootElement); case FeliCa: return FelicaCard.fromXml(id, scannedAt, rootElement); default: throw new UnsupportedOperationException("Unsupported card type: " + type); } }