List of usage examples for org.w3c.dom Node getNodeValue
public String getNodeValue() throws DOMException;
From source file:com.ruzhi.demo.lifeserverweb.StringUtil.java
/** * html/*from w w w . j ava 2 s .co m*/ * @return */ /*public static String filterHtmlTag(String html){ try { StringBuffer sb=new StringBuffer(); DOMFragmentParser parser = new DOMFragmentParser(); HTMLDocument document = new HTMLDocumentImpl(); DocumentFragment fragment = document.createDocumentFragment(); InputSource is = new InputSource(new StringReader(html)); is.setEncoding("GBK"); parser.parse(is, fragment); getText(sb,fragment); return sb.toString(); } catch (SAXException e) { } catch (IOException e) { } return null; }*/ private static void getText(StringBuffer sb, Node node) { if (node.getNodeType() == Node.TEXT_NODE) { sb.append(node.getNodeValue());//???? } NodeList children = node.getChildNodes(); if (children != null) { int len = children.getLength(); for (int i = 0; i < len; i++) { getText(sb, children.item(i));//??DOM } } }
From source file:org.owasp.benchmark.tools.BenchmarkCrawler.java
public static String getAttributeValue(String name, Node node) { if (node == null) { return null; }/*from ww w . j av a 2s . c o m*/ NamedNodeMap nnm = node.getAttributes(); if (nnm != null) { Node attrnode = nnm.getNamedItem(name); if (attrnode != null) { String value = attrnode.getNodeValue(); if (value.equals("[random]")) { value = getToken(); } //System.out.println("El value es: " + value); return value; } } return null; }
From source file:Main.java
public static String getNodeValue(Node node) { if (node instanceof Comment) { return null; }/* w w w .j a v a2 s. co m*/ if (node instanceof CharacterData) { return ((CharacterData) node).getData(); } if (node instanceof EntityReference) { return node.getNodeValue(); } if (node instanceof Element) { return getTextValue((Element) node); } return node.getNodeValue(); }
From source file:jp.go.nict.langrid.bpel.entity.PartnerLink.java
private static String getAttr(NamedNodeMap attrs, String name) { Node attr = attrs.getNamedItem(name); if (attr == null) return null; else//from w w w .ja va2 s. c om return attr.getNodeValue(); }
From source file:eu.planets_project.services.utils.cli.CliMigrationPaths.java
private static String decodeCommandNode(Node command) { Node commandtext = command.getFirstChild(); if (commandtext.getNodeType() == Node.TEXT_NODE) { return commandtext.getNodeValue(); }/*from w w w .j a va2 s. com*/ return ""; }
From source file:com.iggroup.oss.restdoclet.plugin.util.XmlUtils.java
/** * Returns an attribute of a XML node. Leading and trailing whitespaces are * removed in the attribute.// ww w.j a v a 2s . co m * * @param node the XML node. * @param name the name of the attribute. * @return the attribute or <code>null</code> if the attribute is not * present. */ public static String attribute(final Node node, final String name) { String value; if (node.getAttributes() == null) { value = null; } else { final Node attribute = node.getAttributes().getNamedItem(name); if (attribute == null) { value = null; } else { value = trimToNull(attribute.getNodeValue()); } } return value; }
From source file:Main.java
private static boolean equalElements(final Element a, final Element b) { if (!a.getTagName().equals(b.getTagName())) { return false; }// w w w. j a v a 2 s . c o m final NamedNodeMap attributes = a.getAttributes(); int customAttributeCounter = 0; for (int i = 0, n = attributes.getLength(); i < n; i++) { final Node node = attributes.item(i); if (node != null && !node.getNodeName().startsWith("_")) { if (!node.getNodeName().equals("z") && (b.getAttribute(node.getNodeName()).length() == 0 || !b.getAttribute(node.getNodeName()).equals(node.getNodeValue()))) { return false; } } else { customAttributeCounter++; } } if (a.getAttributes().getLength() - customAttributeCounter != b.getAttributes().getLength()) { return false; } return true; }
From source file:Main.java
public static String format(Node n, int indentLevel) { String indent = ""; for (int i = 0; i < indentLevel; i++) { indent += "\t"; }/*from ww w . ja va 2 s . co m*/ StringBuilder result = new StringBuilder(); result.append(indent); if (n.getNodeType() == Node.ELEMENT_NODE) { result.append("<"); result.append(n.getNodeName()); NamedNodeMap attrs = n.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Node attr = attrs.item(i); result.append(" "); result.append(attr.getNodeName()); result.append("=\""); result.append(attr.getNodeValue()); result.append("\""); } result.append(">\n"); } if (n.getNodeType() == Node.TEXT_NODE) { String str = n.getNodeValue(); result.append(str + "\n"); } NodeList childNodes = n.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node n2 = childNodes.item(i); if (isEmptyTextNode(n2)) { continue; } result.append(format(n2, indentLevel + 1)); } if (n.getNodeType() == Node.ELEMENT_NODE) { result.append(indent); result.append("</"); result.append(n.getNodeName()); result.append(">\n"); } return result.toString(); }
From source file:com.enioka.jqm.tools.ResourceParser.java
private static void importXml() throws NamingException { InputStream is = ResourceParser.class.getClassLoader().getResourceAsStream(Helpers.resourceFile); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); try {//w ww.j ava 2s . c o m DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(is); doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName("resource"); String jndiAlias = null, resourceClass = null, description = "no description", scope = null, auth = "Container", factory = null; boolean singleton = false; for (int i = 0; i < nList.getLength(); i++) { Node n = nList.item(i); Map<String, String> otherParams = new HashMap<String, String>(); NamedNodeMap attrs = n.getAttributes(); for (int j = 0; j < attrs.getLength(); j++) { Node attr = attrs.item(j); String key = attr.getNodeName(); String value = attr.getNodeValue(); if ("name".equals(key)) { jndiAlias = value; } else if ("type".equals(key)) { resourceClass = value; } else if ("description".equals(key)) { description = value; } else if ("factory".equals(key)) { factory = value; } else if ("auth".equals(key)) { auth = value; } else if ("singleton".equals(key)) { singleton = Boolean.parseBoolean(value); } else { otherParams.put(key, value); } } if (resourceClass == null || jndiAlias == null || factory == null) { throw new NamingException("could not load the resource.xml file"); } JndiResourceDescriptor jrd = new JndiResourceDescriptor(resourceClass, description, scope, auth, factory, singleton); for (Map.Entry<String, String> prm : otherParams.entrySet()) { jrd.add(new StringRefAddr(prm.getKey(), prm.getValue())); } xml.put(jndiAlias, jrd); } } catch (Exception e) { NamingException pp = new NamingException("could not initialize the JNDI local resources"); pp.setRootCause(e); throw pp; } finally { IOUtils.closeQuietly(is); } }
From source file:Main.java
public static String findXslHref(Node node) { int type = node.getNodeType(); if (type == Node.PROCESSING_INSTRUCTION_NODE) { String nodeName = node.getNodeName(); if (nodeName.equalsIgnoreCase("xml-stylesheet")) { String nodeValue = node.getNodeValue(); try { int i = nodeValue.indexOf("href=\""); int j = nodeValue.indexOf("\"", i + 6); String result = nodeValue.substring(i + 6, j); return result; } catch (StringIndexOutOfBoundsException e) { return null; }//from w ww.j a v a2 s. c o m } return null; } else { NodeList children = node.getChildNodes(); int len = children.getLength(); for (int i = 0; i < len; i++) { String result = findXslHref(children.item(i)); if (result != null) return result; } } return null; }