List of usage examples for org.w3c.dom Node TEXT_NODE
short TEXT_NODE
To view the source code for org.w3c.dom Node TEXT_NODE.
Click Source Link
Text
node. From source file:de.betterform.xml.dom.DOMUtil.java
/** * returns a canonical XPath locationpath for a given Node. Each step in the path will contain the positional * predicate of the Element. Example '/root[1]/a[1]/b[2]/c[5]/@d'. This would point to<br/> * to Attribute named 'd'<br/>//w w w.j a v a 2 s . c o m * on 5th Element 'c"<br/> * on 2nd Element 'b'<br/> * on first Element a<br/> * which is a child of the Document Element. * * @param node the Node where to start * @return canonical XPath locationPath for given Node or the empty string if node is null */ public static String getCanonicalPath(Node node) { if (node == null) { return ""; } if (node.getNodeType() == Node.DOCUMENT_NODE) { return "/"; } //add ourselves String canonPath; String ns = node.getNamespaceURI(); String nodeName1 = node.getNodeName(); String nodeName2 = node.getLocalName(); if (ns != null && ns.equals("http://www.w3.org/1999/xhtml") && node.getNodeName().equals(node.getLocalName())) { canonPath = "html:" + node.getNodeName(); } else { canonPath = node.getNodeName(); } if (node.getNodeType() == Node.ATTRIBUTE_NODE) { canonPath = "@" + canonPath; } else if (node.getNodeType() == Node.ELEMENT_NODE) { int position = DOMUtil.getCurrentNodesetPosition(node); //append position if we are an Element canonPath += "[" + position + "]"; } //check for parent - if there's none we're root Node parent = null; if (node.getNodeType() == Node.ELEMENT_NODE || node.getNodeType() == Node.TEXT_NODE) { parent = node.getParentNode(); } else if (node.getNodeType() == Node.ATTRIBUTE_NODE) { parent = ((Attr) node).getOwnerElement(); } if (parent == null) { parent = node.getOwnerDocument().getDocumentElement(); } if (parent.getNodeType() == Node.DOCUMENT_NODE || parent.getNodeType() == Node.DOCUMENT_FRAGMENT_NODE) { canonPath = "/" + canonPath; } else { canonPath = DOMUtil.getCanonicalPath(parent) + "/" + canonPath; } return canonPath; }
From source file:org.red5.server.undertow.UndertowLoader.java
/** * Parses the web.xml and configures the context. * /*ww w. j a v a 2 s .c om*/ * @param webappsPath * @param contextPath * @param info */ @SuppressWarnings("unchecked") public void parseWebXml(String webappsPath, String contextPath, DeploymentInfo info) { File path = new File(webappsPath, contextPath); File webxml = new File(path, "/WEB-INF/web.xml"); if (webxml.exists() && webxml.canRead()) { try { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse(webxml); // normalize text representation doc.getDocumentElement().normalize(); log.trace("Root element of the doc is {}", doc.getDocumentElement().getNodeName()); // to hold our servlets Map<String, ServletInfo> servletMap = new HashMap<String, ServletInfo>(); // to hold our filters Map<String, FilterInfo> filterMap = new HashMap<String, FilterInfo>(); // do context-param - available to the entire scope of the web application NodeList listOfElements = doc.getElementsByTagName("context-param"); int totalElements = listOfElements.getLength(); log.trace("Total no of context-params: {}", totalElements); for (int s = 0; s < totalElements; s++) { Node fstNode = listOfElements.item(s); if (fstNode.getNodeType() == Node.ELEMENT_NODE) { Element fstElmnt = (Element) fstNode; NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("param-name"); Element fstNmElmnt = (Element) fstNmElmntLst.item(0); NodeList fstNm = fstNmElmnt.getChildNodes(); String pName = (fstNm.item(0)).getNodeValue().trim(); log.trace("Param name: {}", pName); NodeList lstNmElmntLst = fstElmnt.getElementsByTagName("param-value"); Element lstNmElmnt = (Element) lstNmElmntLst.item(0); NodeList lstNm = lstNmElmnt.getChildNodes(); String pValue = (lstNm.item(0)).getNodeValue().trim(); log.trace("Param value: {}", pValue); // add the param info.addServletContextAttribute(pName, pValue); } } // do listener listOfElements = doc.getElementsByTagName("listener"); totalElements = listOfElements.getLength(); log.trace("Total no of listeners: {}", totalElements); for (int s = 0; s < totalElements; s++) { Node fstNode = listOfElements.item(s); if (fstNode.getNodeType() == Node.ELEMENT_NODE) { Element fstElmnt = (Element) fstNode; NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("listener-class"); Element fstNmElmnt = (Element) fstNmElmntLst.item(0); NodeList fstNm = fstNmElmnt.getChildNodes(); String pName = (fstNm.item(0)).getNodeValue().trim(); log.trace("Param name: {}", pName); ListenerInfo listener = new ListenerInfo( (Class<? extends EventListener>) info.getClassLoader().loadClass(pName)); info.addListener(listener); } } // do filter listOfElements = doc.getElementsByTagName("filter"); totalElements = listOfElements.getLength(); log.trace("Total no of filters: {}", totalElements); for (int s = 0; s < totalElements; s++) { Node fstNode = listOfElements.item(s); if (fstNode.getNodeType() == Node.ELEMENT_NODE) { Element fstElmnt = (Element) fstNode; NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("filter-name"); Element fstNmElmnt = (Element) fstNmElmntLst.item(0); NodeList fstNm = fstNmElmnt.getChildNodes(); String pName = (fstNm.item(0)).getNodeValue().trim(); log.trace("Param name: {}", pName); NodeList lstNmElmntLst = fstElmnt.getElementsByTagName("filter-class"); Element lstNmElmnt = (Element) lstNmElmntLst.item(0); NodeList lstNm = lstNmElmnt.getChildNodes(); String pValue = (lstNm.item(0)).getNodeValue().trim(); log.trace("Param value: {}", pValue); // create the filter FilterInfo filter = new FilterInfo(pName, (Class<? extends Filter>) info.getClassLoader().loadClass(pValue)); // do init-param - available in the context of a servlet or filter in the web application listOfElements = fstElmnt.getElementsByTagName("init-param"); totalElements = listOfElements.getLength(); log.trace("Total no of init-params: {}", totalElements); for (int i = 0; i < totalElements; i++) { Node inNode = listOfElements.item(i); if (inNode.getNodeType() == Node.ELEMENT_NODE) { Element inElmnt = (Element) inNode; NodeList inNmElmntLst = inElmnt.getElementsByTagName("param-name"); Element inNmElmnt = (Element) inNmElmntLst.item(0); NodeList inNm = inNmElmnt.getChildNodes(); String inName = (inNm.item(0)).getNodeValue().trim(); log.trace("Param name: {}", inName); NodeList inValElmntLst = inElmnt.getElementsByTagName("param-value"); Element inValElmnt = (Element) inValElmntLst.item(0); NodeList inVal = inValElmnt.getChildNodes(); String inValue = (inVal.item(0)).getNodeValue().trim(); log.trace("Param value: {}", inValue); // add the param filter.addInitParam(inName, inValue); } } // do async-supported NodeList ldElmntLst = fstElmnt.getElementsByTagName("async-supported"); if (ldElmntLst != null) { Element ldElmnt = (Element) ldElmntLst.item(0); NodeList ldNm = ldElmnt.getChildNodes(); String pAsync = (ldNm.item(0)).getNodeValue().trim(); log.trace("Async supported: {}", pAsync); filter.setAsyncSupported(Boolean.valueOf(pAsync)); } // add to map filterMap.put(pName, filter); } } // do filter mappings if (!filterMap.isEmpty()) { listOfElements = doc.getElementsByTagName("filter-mapping"); totalElements = listOfElements.getLength(); log.trace("Total no of filter-mappings: {}", totalElements); for (int s = 0; s < totalElements; s++) { Node fstNode = listOfElements.item(s); if (fstNode.getNodeType() == Node.ELEMENT_NODE) { Element fstElmnt = (Element) fstNode; NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("filter-name"); Element fstNmElmnt = (Element) fstNmElmntLst.item(0); NodeList fstNm = fstNmElmnt.getChildNodes(); String pName = (fstNm.item(0)).getNodeValue().trim(); log.trace("Param name: {}", pName); // lookup the filter info FilterInfo filter = filterMap.get(pName); // add the mapping if (filter != null) { NodeList lstNmElmntLst = fstElmnt.getElementsByTagName("url-pattern"); Element lstNmElmnt = (Element) lstNmElmntLst.item(0); NodeList lstNm = lstNmElmnt.getChildNodes(); String pValue = (lstNm.item(0)).getNodeValue().trim(); log.trace("Param value: {}", pValue); // TODO email list and find out why this doesnt match servlet style //filter.addMapping(pValue); } else { log.warn("No servlet found for {}", pName); } } } // add filters info.addFilters(filterMap.values()); } // do servlet listOfElements = doc.getElementsByTagName("servlet"); totalElements = listOfElements.getLength(); log.trace("Total no of servlets: {}", totalElements); for (int s = 0; s < totalElements; s++) { Node fstNode = listOfElements.item(s); if (fstNode.getNodeType() == Node.ELEMENT_NODE) { Element fstElmnt = (Element) fstNode; NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("servlet-name"); Element fstNmElmnt = (Element) fstNmElmntLst.item(0); NodeList fstNm = fstNmElmnt.getChildNodes(); String pName = (fstNm.item(0)).getNodeValue().trim(); log.trace("Param name: {}", pName); NodeList lstNmElmntLst = fstElmnt.getElementsByTagName("servlet-class"); Element lstNmElmnt = (Element) lstNmElmntLst.item(0); NodeList lstNm = lstNmElmnt.getChildNodes(); String pValue = (lstNm.item(0)).getNodeValue().trim(); log.trace("Param value: {}", pValue); // create the servlet ServletInfo servlet = new ServletInfo(pName, (Class<? extends Servlet>) info.getClassLoader().loadClass(pValue)); // parse load on startup NodeList ldElmntLst = fstElmnt.getElementsByTagName("load-on-startup"); if (ldElmntLst != null) { Element ldElmnt = (Element) ldElmntLst.item(0); NodeList ldNm = ldElmnt.getChildNodes(); String pLoad = (ldNm.item(0)).getNodeValue().trim(); log.trace("Load on startup: {}", pLoad); servlet.setLoadOnStartup(Integer.valueOf(pLoad)); } // do init-param - available in the context of a servlet or filter in the web application listOfElements = fstElmnt.getElementsByTagName("init-param"); totalElements = listOfElements.getLength(); log.trace("Total no of init-params: {}", totalElements); for (int i = 0; i < totalElements; i++) { Node inNode = listOfElements.item(i); if (inNode.getNodeType() == Node.ELEMENT_NODE) { Element inElmnt = (Element) inNode; NodeList inNmElmntLst = inElmnt.getElementsByTagName("param-name"); Element inNmElmnt = (Element) inNmElmntLst.item(0); NodeList inNm = inNmElmnt.getChildNodes(); String inName = (inNm.item(0)).getNodeValue().trim(); log.trace("Param name: {}", inName); NodeList inValElmntLst = inElmnt.getElementsByTagName("param-value"); Element inValElmnt = (Element) inValElmntLst.item(0); NodeList inVal = inValElmnt.getChildNodes(); String inValue = (inVal.item(0)).getNodeValue().trim(); log.trace("Param value: {}", inValue); // add the param servlet.addInitParam(inName, inValue); } } // add to the map servletMap.put(servlet.getName(), servlet); } } // do servlet-mapping if (!servletMap.isEmpty()) { listOfElements = doc.getElementsByTagName("servlet-mapping"); totalElements = listOfElements.getLength(); log.trace("Total no of servlet-mappings: {}", totalElements); for (int s = 0; s < totalElements; s++) { Node fstNode = listOfElements.item(s); if (fstNode.getNodeType() == Node.ELEMENT_NODE) { Element fstElmnt = (Element) fstNode; NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("servlet-name"); Element fstNmElmnt = (Element) fstNmElmntLst.item(0); NodeList fstNm = fstNmElmnt.getChildNodes(); String pName = (fstNm.item(0)).getNodeValue().trim(); log.trace("Param name: {}", pName); // lookup the servlet info ServletInfo servlet = servletMap.get(pName); // add the mapping if (servlet != null) { NodeList lstNmElmntLst = fstElmnt.getElementsByTagName("url-pattern"); Element lstNmElmnt = (Element) lstNmElmntLst.item(0); NodeList lstNm = lstNmElmnt.getChildNodes(); String pValue = (lstNm.item(0)).getNodeValue().trim(); log.trace("Param value: {}", pValue); servlet.addMapping(pValue); } else { log.warn("No servlet found for {}", pName); } } } // add servlets to deploy info info.addServlets(servletMap.values()); } // do welcome files listOfElements = doc.getElementsByTagName("welcome-file-list"); totalElements = listOfElements.getLength(); log.trace("Total no of welcome-files: {}", totalElements); for (int s = 0; s < totalElements; s++) { Node fstNode = listOfElements.item(s); if (fstNode.getNodeType() == Node.ELEMENT_NODE) { Element fstElmnt = (Element) fstNode; NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("welcome-file"); Element fstNmElmnt = (Element) fstNmElmntLst.item(0); NodeList fstNm = fstNmElmnt.getChildNodes(); String pName = (fstNm.item(0)).getNodeValue().trim(); log.trace("Param name: {}", pName); // add welcome page info.addWelcomePage(pName); } } // do display name NodeList dNmElmntLst = doc.getElementsByTagName("display-name"); if (dNmElmntLst.getLength() == 1) { Node dNmNode = dNmElmntLst.item(0); if (dNmNode.getNodeType() == Node.TEXT_NODE) { String dName = dNmNode.getNodeValue().trim(); log.trace("Display name: {}", dName); info.setDisplayName(dName); } } // TODO add security stuff } catch (Exception e) { log.warn("Error reading web.xml", e); } } webxml = null; }
From source file:com.moviejukebox.reader.MovieNFOReader.java
/** * Parse Writers from the XML NFO file/*from ww w . j a va 2s .co m*/ * * @param nlElements * @param movie */ private static void parseWriters(List<Node> nlWriters, Movie movie) { // check if we have nodes if (nlWriters == null || nlWriters.isEmpty()) { return; } // check if we should override boolean overrideWriters = OverrideTools.checkOverwriteWriters(movie, NFO_PLUGIN_ID); boolean overridePeopleWriters = OverrideTools.checkOverwritePeopleWriters(movie, NFO_PLUGIN_ID); if (!overrideWriters && !overridePeopleWriters) { // nothing to do if nothing should be overridden return; } Set<String> newWriters = new LinkedHashSet<>(); for (Node nWriter : nlWriters) { NodeList nlChilds = ((Element) nWriter).getChildNodes(); Node nChilds; for (int looper = 0; looper < nlChilds.getLength(); looper++) { nChilds = nlChilds.item(looper); if (nChilds.getNodeType() == Node.TEXT_NODE) { newWriters.add(nChilds.getNodeValue()); } } } if (overrideWriters) { movie.setWriters(newWriters, NFO_PLUGIN_ID); } if (overridePeopleWriters) { movie.setPeopleWriters(newWriters, NFO_PLUGIN_ID); } }
From source file:com.centeractive.ws.builder.soap.XmlUtils.java
public static String getValueForMatch(XmlCursor cursor) { Node domNode = cursor.getDomNode(); String stringValue;//w w w.ja va 2 s. co m if (domNode.getNodeType() == Node.ATTRIBUTE_NODE || domNode.getNodeType() == Node.TEXT_NODE) { stringValue = domNode.getNodeValue(); } else if (cursor.getObject() instanceof XmlAnySimpleType) { stringValue = ((XmlAnySimpleType) cursor.getObject()).getStringValue(); } else { if (domNode.getNodeType() == Node.ELEMENT_NODE) { Element elm = (Element) domNode; if (elm.getChildNodes().getLength() == 1 && !hasContentAttributes(elm)) { stringValue = getElementText(elm); } else { stringValue = cursor.getObject().xmlText( new XmlOptions().setSavePrettyPrint().setSaveOuter().setSaveAggressiveNamespaces()); } } else { stringValue = domNode.getNodeValue(); } } return stringValue; }
From source file:org.dasein.cloud.azure.AzureMethod.java
public @Nonnull int getOperationStatus(String requestID) throws CloudException, InternalException { ProviderContext ctx = provider.getContext(); Document doc = getAsXML(ctx.getAccountNumber(), "/operations/" + requestID); if (doc == null) { return -2; }/*from www . j a v a2 s .c o m*/ NodeList entries = doc.getElementsByTagName("Operation"); Node entry = entries.item(0); NodeList s = entry.getChildNodes(); String status = ""; String httpCode = ""; for (int i = 0; i < s.getLength(); i++) { Node attribute = s.item(i); if (attribute.getNodeType() == Node.TEXT_NODE) { continue; } if (attribute.getNodeName().equalsIgnoreCase("status") && attribute.hasChildNodes()) { status = attribute.getFirstChild().getNodeValue().trim(); continue; } if (status.length() > 0 && !status.equalsIgnoreCase("inProgress")) { if (attribute.getNodeName().equalsIgnoreCase("httpstatuscode") && attribute.hasChildNodes()) { httpCode = attribute.getFirstChild().getNodeValue().trim(); } } } if (status.equalsIgnoreCase("succeeded")) { return HttpServletResponse.SC_OK; } else if (status.equalsIgnoreCase("failed")) { String errMsg = checkError(s, httpCode); throw new CloudException(errMsg); } return -1; }
From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java
private void addElement(SOAPMessage responseMessage, SOAPEnvelope soapEnvelope, Context context, Element elementToAdd, SOAPElement soapElement) throws SOAPException { SOAPElement soapMethodResponseElement = (SOAPElement) soapEnvelope.getBody().getFirstChild(); String targetNamespace = soapMethodResponseElement.getNamespaceURI(); String prefix = soapMethodResponseElement.getPrefix(); String nodeType = elementToAdd.getAttribute("type"); SOAPElement childSoapElement = soapElement; boolean elementAdded = true; boolean bTable = false; if (nodeType.equals("table")) { bTable = true;/* w w w . ja v a2 s . co m*/ /*childSoapElement = soapElement.addChildElement("ArrayOf" + context.transactionName + "_" + tableName + "_Row", ""); if (!context.httpServletRequest.getServletPath().endsWith(".wsl")) { childSoapElement.addAttribute(soapEnvelope.createName("xsi:type"), "soapenc:Array"); }*/ childSoapElement = soapElement.addChildElement(elementToAdd.getNodeName()); } else if (nodeType.equals("row")) { /*String elementType = context.transactionName + "_" + tableName + "_Row"; childSoapElement = soapElement.addChildElement(elementType, "");*/ childSoapElement = soapElement.addChildElement(elementToAdd.getNodeName()); } else if (nodeType.equals("attachment")) { childSoapElement = soapElement.addChildElement(elementToAdd.getNodeName()); if (context.requestedObject instanceof AbstractHttpTransaction) { AttachmentDetails attachment = AttachmentManager.getAttachment(elementToAdd); if (attachment != null) { byte[] raw = attachment.getData(); if (raw != null) childSoapElement.addTextNode(Base64.encodeBase64String(raw)); } /* DON'T WORK YET *\ AttachmentPart ap = responseMessage.createAttachmentPart(new ByteArrayInputStream(raw), elementToAdd.getAttribute("content-type")); ap.setContentId(key); ap.setContentLocation(elementToAdd.getAttribute("url")); responseMessage.addAttachmentPart(ap); \* DON'T WORK YET */ } } else { String elementNodeName = elementToAdd.getNodeName(); String elementNodeNsUri = elementToAdd.getNamespaceURI(); String elementNodePrefix = getPrefix(context.projectName, elementNodeNsUri); XmlSchemaElement xmlSchemaElement = getXmlSchemaElementByName(context.projectName, elementNodeName); boolean isGlobal = xmlSchemaElement != null; if (isGlobal) { elementNodeNsUri = xmlSchemaElement.getQName().getNamespaceURI(); elementNodePrefix = getPrefix(context.projectName, elementNodeNsUri); } // ignore original SOAP message response elements // if ((elementNodeName.toUpperCase().indexOf("SOAP-ENV:") != -1) || ((elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("SOAP-ENV:") != -1)) || // (elementNodeName.toUpperCase().indexOf("SOAPENV:") != -1) || ((elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("SOAPENV:") != -1)) || // (elementNodeName.toUpperCase().indexOf("NS0:") != -1) || ((elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("NS0:") != -1))) { // elementAdded = false; // } if ("http://schemas.xmlsoap.org/soap/envelope/".equals(elementToAdd.getNamespaceURI()) || "http://schemas.xmlsoap.org/soap/envelope/" .equals(elementToAdd.getParentNode().getNamespaceURI()) || elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("NS0:") != -1 || elementNodeName.toUpperCase().indexOf("NS0:") != -1) { elementAdded = false; } else { if (XsdForm.qualified == context.project.getSchemaElementForm() || isGlobal) { if (elementNodePrefix == null) { childSoapElement = soapElement .addChildElement(soapEnvelope.createName(elementNodeName, prefix, targetNamespace)); } else { childSoapElement = soapElement.addChildElement( soapEnvelope.createName(elementNodeName, elementNodePrefix, elementNodeNsUri)); } } else { childSoapElement = soapElement.addChildElement(elementNodeName); } } } if (elementAdded && elementToAdd.hasAttributes()) { addAttributes(responseMessage, soapEnvelope, context, elementToAdd.getAttributes(), childSoapElement); } if (elementToAdd.hasChildNodes()) { NodeList childNodes = elementToAdd.getChildNodes(); int len = childNodes.getLength(); if (bTable) { /*if (!context.httpServletRequest.getServletPath().endsWith(".wsl")) { childSoapElement.addAttribute(soapEnvelope.createName("soapenc:arrayType"), context.projectName+"_ns:" + context.transactionName + "_" + tableName + "_Row[" + (len - 1) + "]"); }*/ } org.w3c.dom.Node node; Element childElement; for (int i = 0; i < len; i++) { node = childNodes.item(i); switch (node.getNodeType()) { case org.w3c.dom.Node.ELEMENT_NODE: childElement = (Element) node; addElement(responseMessage, soapEnvelope, context, childElement, childSoapElement); break; case org.w3c.dom.Node.CDATA_SECTION_NODE: case org.w3c.dom.Node.TEXT_NODE: String text = node.getNodeValue(); text = (text == null) ? "" : text; childSoapElement.addTextNode(text); break; default: break; } } /*org.w3c.dom.Node node; Element childElement; for (int i = 0 ; i < len ; i++) { node = childNodes.item(i); if (node instanceof Element) { childElement = (Element) node; addElement(responseMessage, soapEnvelope, context, childElement, childSoapElement); } else if (node instanceof CDATASection) { Node textNode = XMLUtils.findChildNode(elementToAdd, org.w3c.dom.Node.CDATA_SECTION_NODE); String text = textNode.getNodeValue(); if (text == null) { text = ""; } childSoapElement.addTextNode(text); } else { Node textNode = XMLUtils.findChildNode(elementToAdd, org.w3c.dom.Node.TEXT_NODE); if (textNode != null) { String text = textNode.getNodeValue(); if (text == null) { text = ""; } childSoapElement.addTextNode(text); } } }*/ } }
From source file:autohit.creator.compiler.SimCompiler.java
/** * Get the text out of an XML node./*from w w w .j a v a2 s . c om*/ * * @param cdn XML node. * @return the text. */ private String getText(Node cdn) { try { if ((cdn.getNodeType() == Node.TEXT_NODE) || (cdn.getNodeType() != Node.CDATA_SECTION_NODE)) { CharacterData cdnc = (CharacterData) cdn; return cdnc.getData(); } } catch (Exception e) { } // ignore. re are returning empty anyway return null; }
From source file:org.dasein.cloud.azure.AzureMethod.java
private String checkError(NodeList s, String httpCode) throws CloudException, InternalException { String errMsg = httpCode + ": "; for (int i = 0; i < s.getLength(); i++) { Node attribute = s.item(i); if (attribute.getNodeType() == Node.TEXT_NODE) { continue; }/*www .j a v a2s.c o m*/ if (attribute.getNodeName().equalsIgnoreCase("Error") && attribute.hasChildNodes()) { NodeList errors = attribute.getChildNodes(); for (int error = 0; error < errors.getLength(); error++) { Node node = errors.item(error); if (node.getNodeName().equalsIgnoreCase("code") && node.hasChildNodes()) { errMsg = errMsg + node.getFirstChild().getNodeValue().trim(); continue; } if (node.getNodeName().equalsIgnoreCase("message") && node.hasChildNodes()) { errMsg = errMsg + ". reason: " + node.getFirstChild().getNodeValue().trim(); } } } } return errMsg; }
From source file:com.centeractive.ws.builder.soap.XmlUtils.java
public static String getValueForMatch(Node domNode, boolean prettyPrintXml) { String stringValue;// ww w . j ava 2 s . com if (domNode.getNodeType() == Node.ATTRIBUTE_NODE || domNode.getNodeType() == Node.TEXT_NODE) { stringValue = domNode.getNodeValue(); } else { if (domNode.getNodeType() == Node.ELEMENT_NODE) { Element elm = (Element) domNode; if (elm.getChildNodes().getLength() == 1 && !hasContentAttributes(elm)) { stringValue = getElementText(elm); } else { stringValue = XmlUtils.serialize(domNode, prettyPrintXml); } } else { stringValue = domNode.getNodeValue(); } } return stringValue; }
From source file:jef.tools.XMLUtils.java
/** * Element(??)// w w w . j a v a 2 s.c o m * * @param node * * @param tagName * ????nullElement * @return ?? */ public static List<Element> childElements(Node node, String... tagName) { if (node == null) throw new NullPointerException("the input node can not be null!"); List<Element> list = new ArrayList<Element>(); NodeList nds = node.getChildNodes(); if (tagName.length == 0 || tagName[0] == null) {// ?API tagName = null; } for (int i = 0; i < nds.getLength(); i++) { Node child = nds.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) child; if (tagName == null || ArrayUtils.contains(tagName, e.getNodeName())) { list.add(e); } } else if (child.getNodeType() == Node.CDATA_SECTION_NODE) { } else if (child.getNodeType() == Node.COMMENT_NODE) { } else if (child.getNodeType() == Node.DOCUMENT_FRAGMENT_NODE) { } else if (child.getNodeType() == Node.DOCUMENT_NODE) { } else if (child.getNodeType() == Node.DOCUMENT_TYPE_NODE) { } else if (child.getNodeType() == Node.ATTRIBUTE_NODE) { } else if (child.getNodeType() == Node.TEXT_NODE) { } } return list; }