List of usage examples for org.w3c.dom Element getTagName
public String getTagName();
From source file:Main.java
private static RSSItem readItem(NodeList nodes) { RSSItem item = new RSSItem(); for (int i = 0; i < nodes.getLength(); ++i) { Node node = nodes.item(i); if (node instanceof Element) { Element elem = (Element) node; if (elem.getTagName().equalsIgnoreCase("title")) { item.setTitle(getText(elem)); } else if (elem.getTagName().equalsIgnoreCase("link")) { item.setLink(getText(elem)); } else if (elem.getTagName().equalsIgnoreCase("description")) { item.setDescription(getText(elem)); } else if (elem.getTagName().equalsIgnoreCase("pubDate")) { item.setPubDate(getText(elem)); } else if (elem.getTagName().equalsIgnoreCase("guid")) { item.setGuid(getText(elem)); }// w w w . j a v a 2s . co m } } return item; }
From source file:Main.java
/** * Get the QName of the passed element. If the passed element has no namespace * URI, only the tag name is used. Otherwise namespace URI, local name and * prefix are used./*from w w w . ja va 2 s. c o m*/ * * @param aElement * The element to be used. May not be <code>null</code>. * @return The created {@link QName}. * @since 8.4.1 */ @Nonnull public static QName getQName(@Nonnull final Element aElement) { final String sNamespaceURI = aElement.getNamespaceURI(); if (sNamespaceURI == null) return new QName(aElement.getTagName()); return new QName(sNamespaceURI, aElement.getLocalName(), getPrefix(aElement)); }
From source file:Main.java
/** * Get the name from the supplied element. * Returns the {@link Node#getLocalName() localName} of the element * if set (namespaced element), otherwise the * element's {@link Element#getTagName() tagName} is returned. * @param element The element.// w w w . j a v a 2 s .c o m * @return The element name. */ public static String getName(Element element) { String name = element.getLocalName(); if (name != null) { return name; } else { return element.getTagName(); } }
From source file:Main.java
public static List<Element> getElementsByTagNameNS(Element parent, String uri, String name, boolean localOnly) { List<Element> ret = new ArrayList<Element>(); if (!localOnly) { NodeList elementList = parent.getElementsByTagNameNS(uri, name); for (int i = 0; i < elementList.getLength(); i++) { ret.add((Element) elementList.item(i)); }/*from w w w .j a va2s . c om*/ } else { NodeList childList = parent.getChildNodes(); for (int i = 0; i < childList.getLength(); i++) { if (childList.item(i).getNodeType() != Node.ELEMENT_NODE) continue; Element child = (Element) childList.item(i); if ((uri.equals("*") || child.getNamespaceURI().equals(uri)) && ((child.getLocalName() == null && uri.equals("*") && child.getTagName().equals(name)) || child.getLocalName().equals(name))) ret.add(child); } } return ret; }
From source file:com.twinsoft.convertigo.engine.AttachmentManager.java
static public AttachmentDetails getAttachment(Element eAttachment) { try {// ww w.jav a 2s . c o m if ("attachment".equals(eAttachment.getTagName()) && "attachment".equals(eAttachment.getAttribute("type"))) { String attr; final String name = eAttachment.getAttribute("name"); final String contentType = eAttachment.getAttribute("content-type"); final byte[][] data = new byte[1][]; if ((attr = eAttachment.getAttribute("local-url")) != null && attr.length() > 0) { FileInputStream fis = null; try { fis = new FileInputStream(attr); fis.read(data[0] = new byte[fis.available()]); } finally { if (fis != null) fis.close(); } } else if ((attr = eAttachment.getAttribute("encoding")) != null && attr.length() > 0) { if ("base64".equals(attr)) { data[0] = Base64.decodeBase64(eAttachment.getTextContent()); } } if (data[0] != null) { return new AttachmentDetails() { public byte[] getData() { return data[0]; } public String getName() { return name; } public String getContentType() { return contentType; } }; } } } catch (Exception e) { Engine.logEngine.error("failed to make AttachmentDetails", e); } return null; }
From source file:Main.java
/** * * @param element//from www. j ava2s. com * @param attributeName * @param sequence * @param matches * @return */ private static int addAttributeLoopElement(Element element, String attributeName, int sequence, String... matches) { int seqNo = sequence; if (matches(element.getTagName(), matches)) { String seq = "00000000000000000000" + seqNo++; seq = seq.substring(seq.length() - 20); element.setAttribute(attributeName, attributeName + "_" + seq); } NodeList nodeList = element.getChildNodes(); int length = nodeList.getLength(); for (int seq = 0; seq < length; seq++) { Node node = nodeList.item(seq); if (node.getNodeType() == Node.ELEMENT_NODE) { seqNo = addAttributeLoopElement((Element) node, attributeName, seqNo, matches); } } return seqNo; }
From source file:Main.java
/** * * @param element//from www.j a va2s. com * @param attributeName * @param matches */ private static void removeAttributeLoopElement(Element element, String attributeName, String... matches) { if (element.hasAttribute(attributeName)) { if (matches(element.getTagName(), matches)) { element.removeAttribute(attributeName); } } NodeList nodeList = element.getChildNodes(); int length = nodeList.getLength(); for (int seq = 0; seq < length; seq++) { Node node = nodeList.item(seq); if (node.getNodeType() == Node.ELEMENT_NODE) { if (element.hasAttribute(attributeName)) { if (matches(element.getTagName(), matches)) { removeAttributeLoopElement((Element) node, attributeName, matches); } } } } }
From source file:Main.java
private static void serializeElement(StringBuilder sb, Element element, int tabIndex) { sb.append('\n'); for (int i = 0; i < tabIndex; i++) { sb.append('\t'); }/*from w w w . jav a 2 s.c o m*/ sb.append("<"); sb.append(element.getTagName()); if (element.hasAttributes()) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); sb.append(" "); sb.append(attribute.getNodeName()); sb.append("="); sb.append("\""); String value = attribute.getNodeValue(); sb.append(value.replace("\"", "\\\"")); sb.append("\""); } } sb.append(">"); NodeList nodeList = element.getChildNodes(); ArrayList<Element> childElements = new ArrayList<Element>(); for (int i = 0; i < nodeList.getLength(); i++) { Node childNode = nodeList.item(i); if (childNode instanceof Element) { childElements.add((Element) childNode); } } if (childElements.size() == 0) { sb.append(escapeInvalidCharacters(getTextContent(element))); } else { for (Element childElement : childElements) { serializeElement(sb, childElement, tabIndex + 1); } sb.append('\n'); for (int i = 0; i < tabIndex; i++) { sb.append('\t'); } } sb.append("</"); sb.append(element.getTagName()); sb.append(">"); }
From source file:com.liferay.ide.layouttpl.core.util.LayoutTplUtil.java
public static List<Element> getChildElementsByTagName(IDOMElement parentElement, String childElementTag) { final NodeList childNodes = ((Node) parentElement).getChildNodes(); List<Element> childElements = new ArrayList<Element>(); for (int i = 0; i < childNodes.getLength(); i++) { Node childNode = childNodes.item(i); if (childNode.getNodeType() == 1 && childElementTag != null) { Element element = (Element) childNode; if (element.getTagName().equals(childElementTag)) { childElements.add(element); }//from w w w . ja v a 2s . c o m } } return childElements; }
From source file:com.bluexml.xforms.actions.EnumAction.java
private static void addValue(Element element, Map<String, String> values, Map<String, String> keys) { String id = null;//ww w .ja v a2 s . com String value = null; NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(i); if (child instanceof Element) { Element e = (Element) child; if (StringUtils.equals(e.getTagName(), "id")) { id = e.getTextContent(); } if (StringUtils.equals(e.getTagName(), "value")) { value = e.getTextContent(); } } } if (id != null && value != null) { values.put(id, value); keys.put(value, id); } }