// factory private static GenerationTarget createTarget(File templateFile, File root) { GenerationTarget target; // read XML document DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); try { DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); Document doc = docBuilder.parse(templateFile); // get name NodeList nodes = doc.getElementsByTagName("templates"); Node node = nodes.item(0); NamedNodeMap attrs = node.getAttributes(); Node attr = attrs.getNamedItem("name"); String templateName = attr.getNodeValue(); target = new GenerationTarget(templateFile, root, templateName); // get class directives nodes = doc.getElementsByTagName("project"); int nb = nodes.getLength(); for (int i = 0; i < nb; i++) { node = nodes.item(i); createProjectDirective(target, node); } } catch (ParserConfigurationException ex) { target = null; } catch (IOException ex) { target = null; } catch (SAXException ex) { target = null; } // end try return target; }
/** * Parses a given .svg for nodes * * @return <b>bothNodeLists</b> an Array with two NodeLists */ public static NodeList[] parseSVG(Date date) { /* As it has to return two things, it can not return them * directly but has to encapsulate it in another object. */ NodeList[] bothNodeLists = new NodeList[2]; ; try { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); String SVGFileName = "./draw_map_svg.svg"; File svgMap = new File(SVGFileName); System.out.println("Parsing the svg"); // Status message #1 Parsing System.out.println("This should not longer than 30 seconds"); // Status message #2 Parsing Document doc = docBuilder.parse(SVGFileName); // "text" is the actual planet/warplanet NodeList listOfPlanetsAsXMLNode = doc.getElementsByTagName("text"); // "line" is the line drawn by a warplanet. Used for calculation of warplanet coordinates. NodeList listOfLinesAsXMLNode = doc.getElementsByTagName("line"); bothNodeLists[0] = listOfPlanetsAsXMLNode; bothNodeLists[1] = listOfLinesAsXMLNode; // normalize text representation doc.getDocumentElement().normalize(); // Build the fileName the .svg should be renamed to, using the dateStringBuilder String newSVGFileName = MapTool.dateStringBuilder(MapTool.getKosmorDate(date), date); newSVGFileName = newSVGFileName.concat(" - Map - kosmor.com - .svg"); // Making sure the directory does exist, if not, it is created File svgdir = new File("svg"); if (!svgdir.exists() || !svgdir.isDirectory()) { svgdir.mkdir(); } svgMap.renameTo(new File(svgdir + "\\" + newSVGFileName)); System.out.println("Done parsing"); // Status message #3 Parsing } catch (SAXParseException err) { System.out.println( "** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId()); System.out.println(" " + err.getMessage()); } catch (SAXException e) { Exception x = e.getException(); ((x == null) ? e : x).printStackTrace(); } catch (Throwable t) { t.printStackTrace(); } return bothNodeLists; }
/** * Carries out preprocessing that makes JEuclid handle the document better. * * @param doc Document */ static void preprocessForJEuclid(Document doc) { // underbrace and overbrace NodeList list = doc.getElementsByTagName("mo"); for (int i = 0; i < list.getLength(); i++) { Element mo = (Element) list.item(i); String parentName = ((Element) mo.getParentNode()).getTagName(); if (parentName == null) { continue; } if (parentName.equals("munder") && isTextChild(mo, "\ufe38")) { mo.setAttribute("stretchy", "true"); mo.removeChild(mo.getFirstChild()); mo.appendChild(doc.createTextNode("\u23df")); } else if (parentName.equals("mover") && isTextChild(mo, "\ufe37")) { mo.setAttribute("stretchy", "true"); mo.removeChild(mo.getFirstChild()); mo.appendChild(doc.createTextNode("\u23de")); } } // menclose for long division doesn't allow enough top padding. Oh, and // <mpadded> isn't implemented. And there isn't enough padding to left of // the bar either. Solve by adding an <mover> with just an <mspace> over# // the longdiv, contained within an mrow that adds a <mspace> before it. list = doc.getElementsByTagName("menclose"); for (int i = 0; i < list.getLength(); i++) { Element menclose = (Element) list.item(i); // Only for longdiv if (!"longdiv".equals(menclose.getAttribute("notation"))) { continue; } Element mrow = doc.createElementNS(WebMathsService.NS, "mrow"); Element mover = doc.createElementNS(WebMathsService.NS, "mover"); Element mspace = doc.createElementNS(WebMathsService.NS, "mspace"); Element mspaceW = doc.createElementNS(WebMathsService.NS, "mspace"); boolean previousElement = false; for (Node previous = menclose.getPreviousSibling(); previous != null; previous = previous.getPreviousSibling()) { if (previous.getNodeType() == Node.ELEMENT_NODE) { previousElement = true; break; } } if (previousElement) { mspaceW.setAttribute("width", "4px"); } menclose.getParentNode().insertBefore(mrow, menclose); menclose.getParentNode().removeChild(menclose); mrow.appendChild(mspaceW); mrow.appendChild(mover); mover.appendChild(menclose); mover.appendChild(mspace); } }
public apiParser(String sdkfile) { System.out.println(sdkfile); File file = new File(sdkfile); try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(file); NodeList apiList = doc.getElementsByTagName("n1:api"); NodeList inputList = doc.getElementsByTagName("n1:input"); NodeList typeList = doc.getElementsByTagName("n1:type"); for (int i = 0; i < apiList.getLength(); i++) { Node api_node = apiList.item(i); String api_id = api_node.getAttributes().getNamedItem("id").getNodeValue(); String api_name = api_node.getAttributes().getNamedItem("name").getNodeValue(); String input_type_id = inputList.item(i).getAttributes().getNamedItem("type_ref").getNodeValue(); // System.out.println(api_id + " : " + api_name + " : " + input_type_id); ArrayList<String> api_params = new ArrayList<String>(); for (int j = 0; j < typeList.getLength(); j++) { if (input_type_id.equalsIgnoreCase( typeList.item(j).getAttributes().getNamedItem("id").getNodeValue())) { Element e1 = (Element) typeList.item(j); NodeList param_l = e1.getElementsByTagName("n1:param"); for (int k = 0; k < param_l.getLength(); k++) { String param_name = param_l.item(k).getAttributes().getNamedItem("name").getNodeValue(); // String param_desc = // param_l.item(k).getAttributes().getNamedItem("desc").getNodeValue(); api_params.add(param_name); // System.out.println(param_name +":"+param_desc); } break; } } apiRoom s_room = new apiRoom(api_id, api_name, api_params); apiRooms.add(s_room); } } catch (Exception e) { e.printStackTrace(); } }
public MapFileReader(String path) { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(new File(path.replace(".data", ".xml"))); NodeList nList = document.getElementsByTagName("map"); background = ((Element) nList.item(0)).getElementsByTagName("File").item(0).getTextContent(); nList = document.getElementsByTagName("vertex"); GraphModel g2 = new GraphModel(false); g2.setAllowLoops(true); Vertex root = new Vertex(); root.setLocation(new GraphPoint(0, 0)); g2.addVertex(root); for (int temp = 0; temp < nList.getLength(); temp++) { Node nNode = nList.item(temp); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; boolean isRoot = eElement.getAttribute("type").equals("root"); String id = eElement.getAttribute("id"); int x = Integer.parseInt(eElement.getElementsByTagName("x").item(0).getTextContent()); int y = Integer.parseInt(eElement.getElementsByTagName("y").item(0).getTextContent()); int value = 0; Vertex newVertex = new Vertex(); newVertex.setLocation(new GraphPoint(x, y)); newVertex.setLabel(id); if (!isRoot) { g2.addVertex(newVertex); value = Integer.parseInt(eElement.getElementsByTagName("value").item(0).getTextContent()); Edge e = new Edge(newVertex, root); e.setWeight(value); g2.addEdge(e); } else { root.setLocation(newVertex.getLocation()); root.setLabel(newVertex.getLabel()); // root = newVertex; } } } this.setGraph(g2); } catch (DOMException | ParserConfigurationException | SAXException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
private void initAllowedHosts(Document pDoc) { NodeList nodes = pDoc.getElementsByTagName("remote"); if (nodes.getLength() == 0) { // No restrictions found allowedHostsSet = null; return; } allowedHostsSet = new HashSet<String>(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); NodeList childs = node.getChildNodes(); for (int j = 0; j < childs.getLength(); j++) { Node hostNode = childs.item(j); if (hostNode.getNodeType() != Node.ELEMENT_NODE) { continue; } assertNodeName(hostNode, "host"); String host = hostNode.getTextContent().trim().toLowerCase(); if (SUBNET_PATTERN.matcher(host).matches()) { if (allowedSubnetsSet == null) { allowedSubnetsSet = new HashSet<String>(); } allowedSubnetsSet.add(host); } else { allowedHostsSet.add(host); } } } }
/** * Runs the test case. * * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList genderList; Node genderNode; Node entText; EntityReference entReference; Node appendedChild; doc = (Document) load("staff", true); genderList = doc.getElementsByTagName("gender"); genderNode = genderList.item(2); entReference = doc.createEntityReference("ent3"); assertNotNull("createdEntRefNotNull", entReference); appendedChild = genderNode.appendChild(entReference); entText = entReference.getFirstChild(); assertNotNull("entTextNotNull", entText); { boolean success = false; try { ((CharacterData) /*Node */ entText).deleteData(1, 3); } catch (DOMException ex) { success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR); } assertTrue("throw_NO_MODIFICATION_ALLOWED_ERR", success); } }
// Lee la configuracion que se encuentra en conf/RegistryConf private void readConfXml() { try { File inputFile = new File("src/java/Conf/RegistryConf.xml"); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(inputFile); doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName("RegistryConf"); for (int i = 0; i < nList.getLength(); i++) { Node nNode = nList.item(i); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; RegistryConf reg = new RegistryConf(); String aux; int idSensor; int value; aux = eElement.getElementsByTagName("idSensor").item(0).getTextContent(); idSensor = Integer.parseInt(aux); reg.setIdSensor(idSensor); aux = eElement.getElementsByTagName("saveType").item(0).getTextContent(); reg.setSaveTypeString(aux); aux = eElement.getElementsByTagName("value").item(0).getTextContent(); value = Integer.parseInt(aux); reg.setValue(value); registryConf.add(reg); lastRead.put(idSensor, 0); } } } catch (Exception e) { e.printStackTrace(); } }
/** * Runs the test case. * * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elementList; Node employeeNode; Node childNode; NodeList childNodes; int nodeType; String childName; java.util.List actual = new java.util.ArrayList(); java.util.List expected = new java.util.ArrayList(); expected.add("em"); expected.add("strong"); expected.add("code"); expected.add("sup"); expected.add("var"); expected.add("acronym"); doc = (Document) load("hc_staff", false); elementList = doc.getElementsByTagName("p"); employeeNode = elementList.item(1); childNodes = employeeNode.getChildNodes(); for (int indexN1006C = 0; indexN1006C < childNodes.getLength(); indexN1006C++) { childNode = (Node) childNodes.item(indexN1006C); nodeType = (int) childNode.getNodeType(); childName = childNode.getNodeName(); if (equals(1, nodeType)) { actual.add(childName); } else { assertEquals("textNodeType", 3, nodeType); } } assertEqualsAutoCase("element", "elementNames", expected, actual); }
public int ajouterAlbum(String titreAlbum, String nomArtiste, int anneeAlbum) { if (!existeAlbum(titreAlbum, nomArtiste, anneeAlbum)) { ID++; Element id = document.createElement("id"); id.setTextContent(Integer.toString(ID)); Element titre = document.createElement("titre"); titre.setTextContent(titreAlbum); Element artiste = document.createElement("artiste"); artiste.setTextContent(nomArtiste); Element annee = document.createElement("annee"); annee.setTextContent(Integer.toString(anneeAlbum)); Element qte = document.createElement("qte"); qte.setTextContent(Integer.toString(0)); Element album = document.createElement("album"); album.appendChild(id); album.appendChild(titre); album.appendChild(artiste); album.appendChild(annee); album.appendChild(qte); Element stock = (Element) document.getElementsByTagName("stock").item(0); stock.appendChild(album); try { save(encryptDocument(document), path); } catch (Exception ex) { Logger.getLogger(Inventaire.class.getName()).log(Level.SEVERE, null, ex); } return ID; } return -1; }
private boolean existeAlbum(String titreAlbum, String nomArtiste, int anneeAlbum) { NodeList listeAlbums = document.getElementsByTagName("album"); if (listeAlbums != null) { for (int i = 0; i < listeAlbums.getLength(); ++i) { String titre = ((Element) listeAlbums.item(i)).getElementsByTagName("titre").item(0).getTextContent(); String artiste = ((Element) listeAlbums.item(i)) .getElementsByTagName("artiste") .item(0) .getTextContent(); int annee = Integer.parseInt( ((Element) listeAlbums.item(i)) .getElementsByTagName("annee") .item(0) .getTextContent()); if (titre.equals(titreAlbum) && artiste.equals(nomArtiste) && annee == anneeAlbum) return true; } } else { return true; } return false; }
private Map<String, Artiste> obtenirAlbumsParArtiste() { Map<String, Artiste> artistes = new TreeMap<String, Artiste>(); NodeList listeAlbums = document.getElementsByTagName("album"); for (int i = 0; i < listeAlbums.getLength(); ++i) { String artiste = ((Element) listeAlbums.item(i)).getElementsByTagName("artiste").item(0).getTextContent(); if (artistes.get(artiste) != null) { int annee = Integer.parseInt( ((Element) listeAlbums.item(i)) .getElementsByTagName("annee") .item(0) .getTextContent()); if (artistes.get(artiste).getAlbums().get(annee) != null) { int id = Integer.parseInt( ((Element) listeAlbums.item(i)) .getElementsByTagName("id") .item(0) .getTextContent()); if (artistes.get(artiste).getAlbums().get(annee).getId() != id) { artistes.get(artiste).addAlbum(creerAlbum(((Element) listeAlbums.item(i)))); } } else { artistes.get(artiste).addAlbum(creerAlbum(((Element) listeAlbums.item(i)))); } } else { Artiste newArtiste = new Artiste(artiste); artistes.put(artiste, newArtiste); artistes.get(artiste).addAlbum(creerAlbum(((Element) listeAlbums.item(i)))); } } return artistes; }
public List parsePage(String pageCode) { List sections = new ArrayList(); List folders = new ArrayList(); List files = new ArrayList(); int start = pageCode.indexOf("<div id=\"list-view\" class=\"view\""); int end = pageCode.indexOf("<div id=\"gallery-view\" class=\"view\""); String usefulSection = ""; if (start != -1 && end != -1) { usefulSection = pageCode.substring(start, end); } else { debug("Could not parse page"); } try { DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(usefulSection)); Document doc = db.parse(is); NodeList divs = doc.getElementsByTagName("div"); for (int i = 0; i < divs.getLength(); i++) { Element div = (Element) divs.item(i); boolean isFolder = false; if (div.getAttribute("class").equals("filename")) { NodeList imgs = div.getElementsByTagName("img"); for (int j = 0; j < imgs.getLength(); j++) { Element img = (Element) imgs.item(j); if (img.getAttribute("class").indexOf("folder") > 0) { isFolder = true; } else { isFolder = false; // it's a file } } NodeList anchors = div.getElementsByTagName("a"); Element anchor = (Element) anchors.item(0); String attr = anchor.getAttribute("href"); String fileName = anchor.getAttribute("title"); String fileURL; if (isFolder && !attr.equals("#")) { folders.add(attr); folders.add(fileName); } else if (!isFolder && !attr.equals("#")) { // Dropbox uses ajax to get the file for download, so the url isn't enough. We must be // sneaky here. fileURL = "https://dl.dropbox.com" + attr.substring(23) + "?dl=1"; files.add(fileURL); files.add(fileName); } } } } catch (Exception e) { debug(e.toString()); } sections.add(files); sections.add(folders); return sections; }
private void initMBeanSets(Document pDoc) throws MalformedObjectNameException { for (String tag : new String[] {"allow", "mbeans"}) { NodeList nodes = pDoc.getElementsByTagName(tag); if (nodes.getLength() > 0) { // "allow" and "mbeans" are synonyms if (allow == null) { allow = new MBeanPolicyConfig(); } extractMbeanConfiguration(nodes, allow); } } NodeList nodes = pDoc.getElementsByTagName("deny"); if (nodes.getLength() > 0) { deny = new MBeanPolicyConfig(); extractMbeanConfiguration(nodes, deny); } }
@Test public void test() { browser.navigate().to("http://127.0.0.1:4444"); Document document = JSInterfaceFactory.create(Document.class); List<WebElement> elements = document.getElementsByTagName("html"); assertNotNull(elements); assertEquals(1, elements.size()); }
private void addListenerToAllHyperlinkItems(EventListener listener) { final Document doc = myEngine.getDocument(); if (doc != null) { final NodeList nodeList = doc.getElementsByTagName("a"); for (int i = 0; i < nodeList.getLength(); i++) { ((EventTarget) nodeList.item(i)).addEventListener(EVENT_TYPE_CLICK, listener, false); } } }
/** * Runs the test case. * * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elementList; Element testEmployee; Attr domesticAttr; doc = (Document) load("staff", true); elementList = doc.getElementsByTagName("address"); testEmployee = (Element) elementList.item(0); domesticAttr = testEmployee.getAttributeNode("invalidAttribute"); assertNull("elementGetAttributeNodeNullAssert", domesticAttr); }
public void getClassName() { try { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse(new File("src/resources/classdata.xml")); doc.getDocumentElement().normalize(); NodeList listOfClasses = doc.getElementsByTagName("class"); classes = new String[listOfClasses.getLength()]; amountClasses = listOfClasses.getLength(); String classID; String className; int classIDint; for (int s = 0; s < listOfClasses.getLength(); s++) { Node firstPersonNode = listOfClasses.item(s); if (firstPersonNode.getNodeType() == Node.ELEMENT_NODE) { Element firstClassElement = (Element) firstPersonNode; NodeList idList = firstClassElement.getElementsByTagName("id"); Element idElement = (Element) idList.item(0); NodeList textLNList = idElement.getChildNodes(); classID = ((Node) textLNList.item(0)).getNodeValue().trim(); NodeList NameList = firstClassElement.getElementsByTagName("name"); Element NameElement = (Element) NameList.item(0); NodeList textFNList = NameElement.getChildNodes(); className = ((Node) textFNList.item(0)).getNodeValue().trim(); classIDint = Integer.parseInt(classID); classes[classIDint] = className; } // end of if clause } // end of for loop with s var } catch (SAXParseException err) { System.out.println( "** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId()); System.out.println(" " + err.getMessage()); } catch (SAXException e) { Exception x = e.getException(); ((x == null) ? e : x).printStackTrace(); } catch (Throwable t) { t.printStackTrace(); } // System.exit (0); }
private Integer obtenirQte() { NodeList listeAlbums = document.getElementsByTagName("album"); int qteTotale = 0; for (int i = 0; i < listeAlbums.getLength(); ++i) { int qte = Integer.parseInt( ((Element) listeAlbums.item(i)).getElementsByTagName("qte").item(0).getTextContent()); qteTotale += qte; } return qteTotale; }
public String getProperty(String pPropertyName) { String propertyValue = null; NodeList nodeList = mConfigFileDocument.getElementsByTagName(pPropertyName); int nodeListLength = nodeList.getLength(); if (nodeListLength > 0) { Node firstChildNode = nodeList.item(nodeListLength - 1).getFirstChild(); if (null != firstChildNode) { propertyValue = firstChildNode.getNodeValue(); } } return (propertyValue); }
/** * @param inputStream * @param session * @param sessionName @return * @throws RuntimeException */ public void loadSession(InputStream inputStream, Session session, String sessionName) { log.debug("Load session"); Document document = null; try { document = Utilities.createDOMDocumentFromXmlStream(inputStream); } catch (Exception e) { log.error("Load session error", e); throw new RuntimeException(e); } NodeList tracks = document.getElementsByTagName("Track"); hasTrackElments = tracks.getLength() > 0; HashMap additionalInformation = new HashMap(); additionalInformation.put(INPUT_FILE_KEY, sessionName); NodeList nodes = document.getElementsByTagName(SessionElement.GLOBAL.getText()); if (nodes == null || nodes.getLength() == 0) { nodes = document.getElementsByTagName(SessionElement.SESSION.getText()); } processRootNode(session, nodes.item(0), additionalInformation); // Add tracks not explicitly allocated to panels. It is legal to define sessions with the // Resources // section only (no Panel or Track elements). addLeftoverTracks(trackDictionary.values()); if (session.getGroupTracksBy() != null && session.getGroupTracksBy().length() > 0) { igv.setGroupByAttribute(session.getGroupTracksBy()); } if (session.isRemoveEmptyPanels()) { igv.getMainPanel().removeEmptyDataPanels(); } igv.resetOverlayTracks(); }
/** * Runs the test case. * * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elementList; Node testEmployee; NamedNodeMap attributes; int length; doc = (Document) load("staff", true); elementList = doc.getElementsByTagName("address"); testEmployee = elementList.item(2); attributes = testEmployee.getAttributes(); length = (int) attributes.getLength(); assertEquals("length", 2, length); }
/** * Runs the test case. * * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; Element elem1; Element elem2; NodeList employeeList; boolean isEqual; doc = (Document) load("hc_staff", false); employeeList = doc.getElementsByTagName("em"); elem1 = (Element) employeeList.item(0); elem2 = (Element) employeeList.item(1); isEqual = elem1.isEqualNode(elem2); assertFalse("nodeisequalnode10", isEqual); }
public static ArrayList<String> getFilterNames() { ArrayList<String> filters = new ArrayList<String>(); try { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse(new File("filters.xml")); // normalize text representation doc.getDocumentElement().normalize(); NodeList listOfPersons = doc.getElementsByTagName("filter"); int totalPersons = listOfPersons.getLength(); System.out.println("Total of filters : " + totalPersons); for (int s = 0; s < listOfPersons.getLength(); s++) { Node firstPersonNode = listOfPersons.item(s); if (firstPersonNode.getNodeType() == Node.ELEMENT_NODE) { Element firstPersonElement = (Element) firstPersonNode; // ------- NodeList firstNameList = firstPersonElement.getElementsByTagName("name"); Element firstNameElement = (Element) firstNameList.item(0); NodeList textFNList = firstNameElement.getChildNodes(); System.out.println("Filter Name : " + ((Node) textFNList.item(0)).getNodeValue().trim()); filters.add(((Node) textFNList.item(0)).getNodeValue().trim()); } // end of if clause } // end of for loop with s var } catch (SAXParseException err) { System.out.println( "** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId()); System.out.println(" " + err.getMessage()); } catch (SAXException e) { Exception x = e.getException(); ((x == null) ? e : x).printStackTrace(); } catch (Throwable t) { t.printStackTrace(); } // System.exit (0); return filters; } // end of main
/** * Runs the test case. * * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elemList; Element elem; String textContent; doc = (Document) load("hc_staff", false); elemList = doc.getElementsByTagName("p"); elem = (Element) elemList.item(2); textContent = elem.getTextContent(); assertEquals( "nodegettextcontent13", "\n EMP0003\n Roger\n Jones\n Department Manager\n 100,000\n Element data\n PO Box 27 Irving, texas 98553\n ", textContent); }
/** * Runs the test case. * * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elementList; Node nameNode; CharacterData child; String childData; doc = (Document) load("staff", true); elementList = doc.getElementsByTagName("address"); nameNode = elementList.item(0); child = (CharacterData) nameNode.getFirstChild(); child.deleteData(0, 16); childData = child.getData(); assertEquals("characterdataDeleteDataBeginingAssert", "Dallas, Texas 98551", childData); }
/** * Runs the test case. * * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList addressList; Node testNode; NamedNodeMap attributes; Attr streetAttr; boolean state; doc = (Document) load("staff", false); addressList = doc.getElementsByTagName("address"); testNode = addressList.item(0); attributes = testNode.getAttributes(); streetAttr = (Attr) attributes.getNamedItem("street"); state = streetAttr.getSpecified(); assertFalse("streetNotSpecified", state); }
public void read(Document doc) { try { Element root = doc.getDocumentElement(); NodeList nList = doc.getElementsByTagName("user"); for (int i = 0; i < nList.getLength(); i++) { Node node = nList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; } } // Element e1 = (Element) nList.item(0); } catch (Exception e) { } }
/** * Runs the test case. * * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList addressList; Node testNode; NamedNodeMap attributes; Attr domesticAttr; Element elementNode; String name; doc = (Document) load("staff", false); addressList = doc.getElementsByTagName("address"); testNode = addressList.item(0); attributes = testNode.getAttributes(); domesticAttr = (Attr) attributes.getNamedItem("domestic"); elementNode = domesticAttr.getOwnerElement(); name = elementNode.getNodeName(); assertEquals("throw_Equals", "address", name); }
private Element obtenirAlbum(int id) { NodeList listeAlbums = document.getElementsByTagName("album"); if (listeAlbums != null) { for (int i = 0; i < listeAlbums.getLength(); ++i) { int courrId = Integer.parseInt( ((Element) listeAlbums.item(i)) .getElementsByTagName("id") .item(0) .getTextContent()); if (courrId == id) return (Element) listeAlbums.item(i); } } else { return null; } return null; }