List of usage examples for org.w3c.dom Document getElementsByTagName
public NodeList getElementsByTagName(String tagname);
NodeList
of all the Elements
in document order with a given tag name and are contained in the document. From source file:org.pentaho.support.cmd.CommandLineUtility.java
/** * parses web.xml file the get pentaho-solution path if installation is * manual/*www . jav a 2 s . c om*/ * * @param server * @param webxml * @return */ private static String getSolutionPath(String server, String webxml) { String pentahoSolPath = null; String os = System.getProperty(CMDConstant.OS).toLowerCase().substring(0, 3); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); File xmlFile = new File(webxml); try { DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(xmlFile); NodeList paramValueList = doc.getElementsByTagName(CMDConstant.XML_PARAM_VALUE); for (int i = 0; i < paramValueList.getLength(); i++) { Node paramNode = paramValueList.item(i); if (paramNode.getTextContent().contains(CMDConstant.PENTAHO_SOL_DIR)) { if (os.equals("win")) { pentahoSolPath = paramNode.getTextContent().replace("/", "\\"); } else { pentahoSolPath = paramNode.getTextContent(); } } } } catch (Exception e) { e.printStackTrace(); } return pentahoSolPath; }
From source file:com.aurel.track.admin.customize.category.report.ReportBL.java
public static Map<String, Object> getTemplateDescription(InputStream is) { Map<String, Object> description = new HashMap<String, Object>(); try {// w ww . j a v a2s . c o m DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(is); doc.getDocumentElement().normalize(); try { NodeList nl = doc.getElementsByTagName("locale"); for (int s = 0; s < nl.getLength(); s++) { Node localeNode = nl.item(s); if (localeNode.getNodeType() == Node.ELEMENT_NODE) { Map<String, String> localizedStuff = new HashMap<String, String>(); String value = ""; String descript = ""; String listing = ""; String toolTip = ""; Element element = (Element) localeNode; descript = getTagValue("description", element).trim(); listing = getTagValue("listing", element).trim(); toolTip = getTagValue("tool-tip", element).trim(); value = element.getAttribute("value"); if (value == null) { value = ""; } localizedStuff.put("listing", listing); localizedStuff.put("description", descript); localizedStuff.put("tool-tip", toolTip); description.put("locale_" + value, localizedStuff); } } } catch (Exception e) { LOGGER.error("Getting the locale elements failed with " + e.getMessage()); } NodeList nl = doc.getDocumentElement().getChildNodes(); for (int s = 0; s < nl.getLength(); s++) { if (nl.item(s).getNodeType() == Node.ELEMENT_NODE) { description.put(nl.item(s).getNodeName(), nl.item(s).getChildNodes().item(0).getNodeValue()); } } } catch (Exception e) { LOGGER.error(e.getMessage()); } return description; }
From source file:com.unitedcoders.android.gpodroid.services.RSSService.java
private static String getImageUrlFromFeed(Context context, String url) { try {//from w w w . j av a2 s .c o m Document doc; DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); DefaultHttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(url); HttpResponse response = client.execute(request); doc = builder.parse(response.getEntity().getContent()); // return doc; // get Image NodeList item = doc.getElementsByTagName("channel"); Element el = (Element) item.item(0); String imageUrl; NodeList imagNode = el.getElementsByTagName("image"); if (imagNode != null) { Element ima = (Element) imagNode.item(0); if (ima != null) { NodeList urlNode = ima.getElementsByTagName("url"); if (urlNode == null || urlNode.getLength() < 1) imageUrl = null; else imageUrl = urlNode.item(0).getFirstChild().getNodeValue(); } else imageUrl = null; } else imageUrl = null; return imageUrl; } catch (IOException e) { return null; // The network probably died, just return null } catch (SAXException e) { // Problem parsing the XML, log and return nothing Log.e("NCRSS", "Error parsing XML", e); return null; } catch (Exception e) { // Anything else was probably another network problem, fail silently return null; } }
From source file:com.omertron.traileraddictapi.tools.TrailerAddictParser.java
public static List<Trailer> getTrailers(URL url) { Document doc; List<Trailer> trailers = new ArrayList<Trailer>(); try {// w w w.j a v a 2s . c om LOG.trace("Attempting to get trailer XML from {}", url.toString()); doc = DOMHelper.getEventDocFromUrl(url.toString()); } catch (TrailerAddictException ex) { LOG.trace("Exception processing document: {}", url.toString(), ex); return trailers; } NodeList nlTrailers = doc.getElementsByTagName("trailer"); Node nTrailer; Element eTrailer; Trailer trailer; for (int loop = 0; loop < nlTrailers.getLength(); loop++) { nTrailer = nlTrailers.item(loop); if (nTrailer.getNodeType() == Node.ELEMENT_NODE) { eTrailer = (Element) nTrailer; trailer = new Trailer(); trailer.setCombinedTitle(DOMHelper.getValueFromElement(eTrailer, "title")); trailer.setLink(DOMHelper.getValueFromElement(eTrailer, "link")); String trailerId = DOMHelper.getValueFromElement(eTrailer, "trailer_id"); if (StringUtils.isNumeric(trailerId)) { trailer.setTrailerId(Integer.parseInt(trailerId)); } trailer.setPublishDate(DOMHelper.getValueFromElement(eTrailer, "pubDate")); trailer.addEmbed(DOMHelper.getValueFromElement(eTrailer, "embed")); // Simple API stuff here trailer.setTrailerTitle(DOMHelper.getValueFromElement(eTrailer, "video_title")); trailer.setDescription(DOMHelper.getValueFromElement(eTrailer, "description")); trailer.setFilmTitle(DOMHelper.getValueFromElement(eTrailer, "film")); trailer.addEmbed(TrailerSize.STANDARD, DOMHelper.getValueFromElement(eTrailer, "embed_standard")); trailer.addEmbed(TrailerSize.SMALL, DOMHelper.getValueFromElement(eTrailer, "embed_small")); trailer.addEmbed(TrailerSize.MEDIUM, DOMHelper.getValueFromElement(eTrailer, "embed_medium")); trailer.addEmbed(TrailerSize.LARGE, DOMHelper.getValueFromElement(eTrailer, "embed_large")); trailer.setDirectors(DOMHelper.getValueFromElement(eTrailer, "director")); trailer.setWriters(DOMHelper.getValueFromElement(eTrailer, "writer")); trailer.setCast(DOMHelper.getValueFromElement(eTrailer, "cast")); trailer.setStudio(DOMHelper.getValueFromElement(eTrailer, "studio")); trailer.setReleaseDate(DOMHelper.getValueFromElement(eTrailer, "release_date")); // Add the trailer to the list trailers.add(trailer); } } LOG.trace("Found {} trailers for {}", trailers.size(), url.toString()); return trailers; }
From source file:Main.java
public static List<Map<String, String>> ReadFolderItemsFromFile(String path, String filename, String folderID) { List<Map<String, String>> results = new ArrayList<Map<String, String>>(); try {//from w ww .j ava2s. c o m File fXmlFile = new File(path, filename); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); NodeList nList = null; if (folderID == null) { // get all the children of the root nList = doc.getChildNodes().item(0).getChildNodes(); } else { //Log.d("ReadItemsFromFile", "Current FolderID: " + folderID); NodeList folderList = doc.getElementsByTagName("folder"); for (int i = 0; i < folderList.getLength(); i++) { Node curNode = folderList.item(i); if (curNode.getNodeType() == Node.ELEMENT_NODE) { String curNodeId = ((Element) curNode).getElementsByTagName("id").item(0).getTextContent(); //Log.d("ReadItemsFromFile", "Number of items: " + curNodeId); if (curNodeId.equals(folderID)) { //Log.d("ReadItemsFromFile", "Found the folder"); NodeList folderChildren = curNode.getChildNodes(); for (int j = 0; j < folderChildren.getLength(); j++) { //Log.d("ReadItemsFromFile", "node name: " + folderChildren.item(j).getNodeName()); if (folderChildren.item(j).getNodeName().equals("contents")) { //Log.d("ReadItemsFromFile", "found the contents child"); nList = folderChildren.item(j).getChildNodes(); break; } } break; } } } } if (nList != null) { Log.d("ReadItemsFromFile", "-----------------------"); Log.d("ReadItemsFromFile", "Number of items: " + nList.getLength()); for (int temp = 0; temp < nList.getLength(); temp++) { Node nNode = nList.item(temp); //Log.d("ReadItemsFromFile", temp + ". node type: " + nNode.getNodeType()); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; Node elementNameNode = eElement.getElementsByTagName("name").item(0); String elementNameString = elementNameNode.getTextContent(); //Log.d("ReadItemsFromFile", "Name: " + elementNameString); HashMap<String, String> mapElement = new HashMap<String, String>(); mapElement.put("name", elementNameString); mapElement.put("id", eElement.getElementsByTagName("id").item(0).getTextContent()); mapElement.put("type", nNode.getNodeName()); results.add(mapElement); } } } } catch (Exception e) { e.printStackTrace(); return null; } return results; }
From source file:com.valco.utility.FacturasUtility.java
public static void agregarDatosDeTimbrado(Facturas factura, String xml) throws ParserConfigurationException, SAXException, IOException, ParseException { String folioFiscal = null;//from w w w . j a v a2s .c o m Date fechaTimbrado = new Date(); String selloCFD = null; String noCertificadoSat = null; String selloSat = null; SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); InputStream inputXml = new ByteArrayInputStream(xml.getBytes("UTF-8")); org.w3c.dom.Document doc = dBuilder.parse(inputXml); doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName("tfd:TimbreFiscalDigital"); for (int temp = 0; temp < nList.getLength(); temp++) { Node nNode = nList.item(temp); System.out.println("\nCurrent Element :" + nNode.getNodeName()); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; folioFiscal = eElement.getAttribute("UUID"); fechaTimbrado = formatDate.parse(eElement.getAttribute("FechaTimbrado")); selloCFD = eElement.getAttribute("selloCFD"); noCertificadoSat = eElement.getAttribute("noCertificadoSAT"); selloSat = eElement.getAttribute("selloSAT"); factura.setFolioFiscal(folioFiscal); factura.setFechaTimbrado(fechaTimbrado); factura.setSelloCdfi(selloCFD); factura.setNoSerieCertSat(noCertificadoSat); factura.setSelloSat(selloSat); } } }
From source file:net.roboconf.agent.internal.misc.UserDataUtils.java
private static String getValueOfTagInXMLFile(String filePath, String tagName) throws ParserConfigurationException, SAXException, IOException { File fXmlFile = new File(filePath); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); // Optional, but recommended // Read this: http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName(tagName); String valueOfTagName = ""; for (int temp = 0; temp < nList.getLength(); temp++) { Node nNode = nList.item(temp); valueOfTagName = nNode.getTextContent(); }//from ww w .j a va2 s . co m return valueOfTagName; }
From source file:com.osafe.services.MelissaDataHelper.java
private static AddressVerificationResponse buildVerificationResponse(Document doc) { AddressVerificationResponse avResponse = new AddressVerificationResponse(); NodeList nodeList = doc.getElementsByTagName("Results").item(0).getChildNodes(); Node nValue = (Node) nodeList.item(0); if (nValue.getNodeValue().equals(" ")) { List<AddressDocument> responseAddresseList = FastList.newInstance(); NodeList recordList = doc.getElementsByTagName("Record"); for (int temp = 0; temp < recordList.getLength(); temp++) { AddressDocument responseAddresse = new AddressDocument(); Node nNode = recordList.item(temp); Element eElement = (Element) nNode; //check result success, changed or error nodeList = eElement.getElementsByTagName("Results").item(0).getChildNodes(); String results = nodeList.item(0).getNodeValue(); setResponseCode(avResponse, results); if (UtilValidate.isEmpty(avResponse.getResponseCode())) { avResponse.setResponseCode(AddressVerificationResponse.AS); }/* w w w. j ava2s . c o m*/ //get address1 nodeList = eElement.getElementsByTagName("Address1").item(0).getChildNodes(); responseAddresse.setAddress1(nodeList.item(0).getNodeValue()); //get address2 nodeList = eElement.getElementsByTagName("Address2").item(0).getChildNodes(); responseAddresse.setAddress2(nodeList.item(0).getNodeValue()); //get City nodeList = eElement.getElementsByTagName("City").item(0).getChildNodes(); responseAddresse.setCity(nodeList.item(0).getChildNodes().item(0).getNodeValue()); //get State nodeList = eElement.getElementsByTagName("State").item(0).getChildNodes(); responseAddresse.setStateProvinceGeoId(nodeList.item(1).getChildNodes().item(0).getNodeValue()); //get Country nodeList = eElement.getElementsByTagName("Country").item(0).getChildNodes(); responseAddresse.setCountryGeoId(nodeList.item(0).getChildNodes().item(0).getNodeValue()); //get Zip nodeList = eElement.getElementsByTagName("Zip").item(0).getChildNodes(); responseAddresse.setPostalCode(nodeList.item(0).getNodeValue()); //get Plus4 nodeList = eElement.getElementsByTagName("Plus4").item(0).getChildNodes(); responseAddresse.setPostalCodeExt(nodeList.item(0).getNodeValue()); responseAddresseList.add(responseAddresse); } avResponse.setAlternateAddresses(responseAddresseList); } else { avResponse.setResponseCode(AddressVerificationResponse.GE); } return avResponse; }
From source file:com.unitedcoders.android.gpodroid.tools.Tools.java
public static String getImageUrlFromFeed(Context context, String url) { try {/*ww w .ja v a2 s .c om*/ Document doc; DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); DefaultHttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(url); HttpResponse response = client.execute(request); doc = builder.parse(response.getEntity().getContent()); // return doc; // get Image NodeList item = doc.getElementsByTagName("channel"); Element el = (Element) item.item(0); String imageUrl; NodeList imagNode = el.getElementsByTagName("image"); if (imagNode != null) { Element ima = (Element) imagNode.item(0); if (ima != null) { NodeList urlNode = ima.getElementsByTagName("url"); if (urlNode == null || urlNode.getLength() < 1) imageUrl = null; else imageUrl = urlNode.item(0).getFirstChild().getNodeValue(); } else imageUrl = null; } else imageUrl = null; return imageUrl; } catch (IOException e) { return null; // The network probably died, just return null } catch (SAXException e) { // Problem parsing the XML, log and return nothing Log.e("NCRSS", "Error parsing XML", e); return null; } catch (Exception e) { // Anything else was probably another network problem, fail silently return null; } }
From source file:it.polimi.diceH2020.plugin.control.FileManager.java
/** * Scans Hadoop model to extract information * //w w w .j a va 2 s . com * @param fileName * XML file path * @return A map containing the parameters extracted from the model */ public static Map<String, String> parseDOMXmlFile(String fileName) { File src = new File(fileName); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; Map<String, String> res = new HashMap<String, String>(); try { builder = factory.newDocumentBuilder(); Document doc = builder.parse(src); NodeList group = doc.getElementsByTagName("group"); for (int i = 0; i < group.getLength(); i++) { Element e = (Element) group.item(i); if (e.getAttribute("name").equals("Reducer")) { String data = group.item(i).getTextContent().trim(); res.put("rTasks", data.substring(data.indexOf('[') + 1, data.indexOf(']'))); res.put("rDemand", data.substring(data.indexOf('x') + 4, data.indexOf('u') - 1)); } if (e.getAttribute("name").equals("Mapper")) { String data = group.item(i).getTextContent().trim(); res.put("mTasks", data.substring(data.indexOf('[') + 1, data.indexOf(']'))); res.put("mDemand", data.substring(data.indexOf('x') + 4, data.indexOf('u') - 1)); } } } catch (ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return res; }