Java Code Examples for org.w3c.dom.Element
The following code examples are extracted from open source projects. You can click to
vote up the examples that are useful to you.
Example 1
From project as3-commons-jasblocks, under directory /src/main/java/org/as3commons/asblocks/impl/.
Source file: SWCResourceRoot.java

private List<ASQName> readCatalog(InputStream in) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException { Document doc=loadDoc(in); XPathFactory fact=XPathFactory.newInstance(); XPath xpath=fact.newXPath(); NodeList list=(NodeList)xpath.evaluate("/swc/libraries/library/script/def",doc,XPathConstants.NODESET); List<ASQName> result=new ArrayList<ASQName>(); for (int i=0; i < list.getLength(); i++) { Element def=(Element)list.item(i); String defined=def.getAttribute("id"); result.add(toQName(defined)); } return result; }
Example 2
From project adt-maven-plugin, under directory /src/main/java/com/yelbota/plugins/adt/model/.
Source file: ApplicationDescriptorModel.java

private void appendExtensionsElementChildren(Element extensionsElement){ for ( String extensionId : extensionIds) { Element extensionsChildElement=dom.createElement("extensionID"); extensionsChildElement.setTextContent(extensionId); extensionsElement.appendChild(extensionsChildElement); } }
Example 3
From project anadix, under directory /anadix-core/src/main/java/org/anadix/impl/.
Source file: XHTMLReportFormatter.java

private static Node createResultTable(Collection<ReportItem> items,Document doc){ Element resultTable=doc.createElement("table"); resultTable.setAttribute("style","border-collapse: separate; border-spacin: 5px 20px;"); for ( ReportItem item : items) { resultTable.appendChild(createResultRow(item,doc)); } return resultTable; }
Example 4
From project any23, under directory /core/src/test/java/org/apache/any23/extractor/rdfa/.
Source file: RDFa11ParserTest.java

@Test public void testUpdateURIMapping() throws ParserConfigurationException { Element div=getRootDocument().createElement("DIV"); div.setAttribute("xmlns:dc","http://purl.org/dc/terms/"); div.setAttribute("xmlns:fake","http://fake.org/"); final RDFa11Parser parser=new RDFa11Parser(); parser.updateURIMapping(div); Assert.assertEquals("http://purl.org/dc/terms/",parser.getMapping("dc").toString()); Assert.assertEquals("http://fake.org/",parser.getMapping("fake").toString()); }
Example 5
private static Element getElementByName(Element element,String name){ Element result=null; NodeList children=element.getElementsByTagName(name); for (int i=0; i < children.getLength(); i++) { Node node=children.item(i); if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(name)) { result=(Element)node; break; } } return result; }
Example 6
From project aranea, under directory /server/src/main/java/no/dusken/aranea/admin/control/.
Source file: ImportStvMediaController.java

/** * I take a xml element and the tag name, look for the tag and get the text content i.e for <employee><name>John</name></employee> xml snippet if the Element points to employee node and tagName is name I will return John */ private String getTextValue(Element ele,String tagName){ String textVal=null; NodeList nl=ele.getElementsByTagName(tagName); if (nl != null && nl.getLength() > 0) { Element el=(Element)nl.item(0); textVal=el.getFirstChild().getNodeValue(); } return textVal; }
Example 7
From project arquillian-rusheye, under directory /rusheye-api/src/main/java/org/jboss/rusheye/suite/.
Source file: Properties.java

public void setProperty(String key,Object value){ Element elementForRemoval=null; for ( Element element : getAny()) { if (element.getLocalName().equals(key)) { elementForRemoval=element; } } if (elementForRemoval != null) { getAny().remove(elementForRemoval); } Element element=new SimpleElement(key); element.setTextContent(value.toString()); getAny().add(element); }
Example 8
From project blueprint-namespaces, under directory /blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/.
Source file: Parser.java

public PropsMetadata parseProps(Element element){ List<MapEntry> entries=new ArrayList<MapEntry>(); NodeList nl=element.getChildNodes(); for (int i=0; i < nl.getLength(); i++) { Node node=nl.item(i); if (node instanceof Element) { Element e=(Element)node; if (isBlueprintNamespace(e.getNamespaceURI()) && nodeNameEquals(e,PROP_ELEMENT)) { entries.add(parseProperty(e)); } } } return builder.newProps().entries(entries); }
Example 9
From project bndtools, under directory /bndtools.core/src/bndtools/launch/.
Source file: BndDependencySourceContainerType.java

public String getMemento(ISourceContainer container) throws CoreException { Document document=newDocument(); Element element=document.createElement("default"); document.appendChild(element); return serializeDocument(document); }
Example 10
From project bpelunit, under directory /net.bpelunit.framework/src/main/java/net/bpelunit/framework/control/util/.
Source file: BPELUnitUtil.java

/** * Creates a new document with a dummy root node, intended to store literal data for a receive or send. CAUTION: This method depends on initialization which is done by calling {@link initializeParsing}. Not initializing this class will cause uncaught NPEs. * @return */ public static Element generateDummyElementNode(){ Document document=fgDocumentBuilder.newDocument(); Element root=document.createElement(DUMMY_ELEMENT_NAME); document.appendChild(root); return root; }
Example 11
From project Absolute-Android-RSS, under directory /src/com/AA/Other/.
Source file: RSSParse.java

/** * Get the list of articles currently contained in the RSS feed. * @param isBackground if the request is being run in the background * @param callingContext current application context * @return List of articles contained in the RSS on success. On failure returns null */ public static List<Article> getArticles(boolean isBackground,Context callingContext){ if (!isNetworkAvailable(isBackground,callingContext)) return null; Document doc=getDocument(); if (doc == null) return null; try { ArrayList<Article> articles=new ArrayList<Article>(); NodeList items=doc.getElementsByTagName("item"); for (int i=0; i < items.getLength(); i++) { Element el=(Element)items.item(i); String title=el.getElementsByTagName("title").item(0).getFirstChild().getNodeValue(); String date=el.getElementsByTagName("pubDate").item(0).getFirstChild().getNodeValue(); String url=el.getElementsByTagName("link").item(0).getFirstChild().getNodeValue(); String desc=el.getElementsByTagName("description").item(0).getFirstChild().getNodeValue(); articles.add(new Article(desc,title,date,url)); } return articles; } catch ( Exception e) { Log.e("AARSS","Error Parsing RSS",e); return null; } }
Example 12
From project Agot-Java, under directory /src/main/java/got/utility/.
Source file: ConnectionCreate.java

/** * saveCenters() Saves the centers to disk. */ private void saveCenters(){ try { final String fileName=new FileSave("Where To Save centers.txt ?","connection.xml").getPathString(); if (fileName == null) { return; } final FileOutputStream out=new FileOutputStream(fileName); DocumentBuilderFactory docFactory=DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder=docFactory.newDocumentBuilder(); Document doc=docBuilder.newDocument(); Element rootElement=doc.createElement("Connections"); doc.appendChild(rootElement); for ( Connection conn : m_conns) { Element connection=doc.createElement("Connection"); rootElement.appendChild(connection); Attr attr=doc.createAttribute("t1"); attr.setValue(conn.start); connection.setAttributeNode(attr); Attr attr1=doc.createAttribute("t2"); attr1.setValue(conn.end); connection.setAttributeNode(attr1); } TransformerFactory transformerFactory=TransformerFactory.newInstance(); Transformer transformer=transformerFactory.newTransformer(); DOMSource source=new DOMSource(doc); StreamResult result=new StreamResult(new File(fileName)); transformer.transform(source,result); System.out.println("Data written to :" + new File(fileName).getCanonicalPath()); } catch ( final FileNotFoundException ex) { ex.printStackTrace(); } catch ( final HeadlessException ex) { ex.printStackTrace(); } catch ( final Exception ex) { ex.printStackTrace(); } }
Example 13
From project Amoeba-for-Aladdin, under directory /src/java/com/meidusa/amoeba/config/.
Source file: DocumentUtil.java

/** * ??amoeba.xml?????property?name?????? * @param current * @return */ public static BeanObjectEntityConfig loadBeanConfig(Element current){ if (current == null) { return null; } BeanObjectEntityConfig beanConfig=new BeanObjectEntityConfig(); NodeList children=current.getChildNodes(); int childSize=children.getLength(); beanConfig.setName(current.getAttribute("name")); Element element=DocumentUtil.getTheOnlyElement(current,"className"); if (element != null) { beanConfig.setClassName(element.getTextContent()); } else { beanConfig.setClassName(current.getAttribute("class")); } Map<String,Object> map=new HashMap<String,Object>(); for (int i=0; i < childSize; i++) { Node childNode=children.item(i); if (childNode instanceof Element) { Element child=(Element)childNode; final String nodeName=child.getNodeName(); if (nodeName.equals("property")) { String key=child.getAttribute("name"); NodeList propertyNodes=child.getElementsByTagName("bean"); if (propertyNodes.getLength() == 0) { String value=child.getTextContent(); map.put(key,StringUtil.isEmpty(value) ? null : value.trim()); } else { BeanObjectEntityConfig beanconfig=loadBeanConfig((Element)propertyNodes.item(0)); map.put(key,beanconfig); } } } } beanConfig.setParams(map); return beanConfig; }
Example 14
From project android-joedayz, under directory /Proyectos/LectorFeeds/src/com/android/joedayz/demo/.
Source file: XMLParser.java

public LinkedList<HashMap<String,String>> parse(){ DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance(); LinkedList<HashMap<String,String>> entries=new LinkedList<HashMap<String,String>>(); HashMap<String,String> entry; try { DocumentBuilder builder=factory.newDocumentBuilder(); Document dom=builder.parse(this.url.openConnection().getInputStream()); Element root=dom.getDocumentElement(); NodeList items=root.getElementsByTagName("item"); for (int i=0; i < items.getLength(); i++) { entry=new HashMap<String,String>(); Node item=items.item(i); NodeList properties=item.getChildNodes(); for (int j=0; j < properties.getLength(); j++) { Node property=properties.item(j); String name=property.getNodeName(); if (name.equalsIgnoreCase("title")) { entry.put(Main.DATA_TITLE,property.getFirstChild().getNodeValue()); } else if (name.equalsIgnoreCase("link")) { entry.put(Main.DATA_LINK,property.getFirstChild().getNodeValue()); } } entries.add(entry); } } catch ( Exception e) { throw new RuntimeException(e); } return entries; }
Example 15
private static XmlDom convert(Node node,String tag,String attr,String value){ if (node.getNodeType() != Node.ELEMENT_NODE) { return null; } Element e=(Element)node; XmlDom result=null; if (tag == null || tag.equals(e.getTagName())) { if (attr == null || e.hasAttribute(attr)) { if (value == null || value.equals(e.getAttribute(attr))) { result=new XmlDom(e); } } } return result; }
Example 16
From project ant4eclipse, under directory /org.ant4eclipse.ant.pde/src/org/ant4eclipse/ant/pde/.
Source file: PatchFeatureManifestTask.java

/** * Replaces the given plug-in-versions in given feature.xml-File. * @param featureXml The feature.xml file. NOTE: this file will be <b>changed</b> and thus must be writable * @param qualifier The new version for this feature. If set to null, the "version"-attribute of the "feature"-tag won't be changed * @param newBundleVersions A map containing plugin-id (String) - version (String) associations * @throws Exception */ protected void replaceVersions(File featureXml,String qualifier,StringMap newBundleVersions) throws Exception { Assure.notNull("featureXml",featureXml); Assure.assertTrue(featureXml.isFile(),"featureXml (" + featureXml + ") must point to an existing file"); DocumentBuilder builder=DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document featureDom=builder.parse(featureXml); if (qualifier != null) { Element featureElement=featureDom.getDocumentElement(); String featureVersion=featureElement.getAttribute("version"); if (featureVersion != null && featureVersion.endsWith(".qualifier")) { featureElement.setAttribute("version",PdeBuildHelper.resolveVersion(new Version(featureVersion),qualifier).toString()); } } NodeList pluginNodes=featureDom.getDocumentElement().getElementsByTagName("plugin"); for (int i=0; i < pluginNodes.getLength(); i++) { Element element=(Element)pluginNodes.item(i); String id=element.getAttribute("id"); if (newBundleVersions.containsKey(id)) { String version=newBundleVersions.get(id); element.setAttribute("version",version); } } DOMSource domSource=new DOMSource(featureDom); Transformer transformer=TransformerFactory.newInstance().newTransformer(); StreamResult result=new StreamResult(featureXml); transformer.transform(domSource,result); }
Example 17
From project autopsy, under directory /Core/src/org/sleuthkit/autopsy/ingest/.
Source file: IngestModuleLoader.java

/** * Save the current in memory pipeline config, including autodiscovered modules * @throws IngestModuleLoaderException */ public void save() throws IngestModuleLoaderException { DocumentBuilderFactory dbfac=DocumentBuilderFactory.newInstance(); try { DocumentBuilder docBuilder=dbfac.newDocumentBuilder(); Document doc=docBuilder.newDocument(); Comment comment=doc.createComment("Saved by: " + getClass().getName() + " on: "+ dateFormatter.format(System.currentTimeMillis())); doc.appendChild(comment); Element rootEl=doc.createElement(IngestModuleLoader.XmlPipelineRaw.XML_PIPELINE_ROOT); doc.appendChild(rootEl); for ( IngestModuleLoader.XmlPipelineRaw rawP : this.pipelinesXML) { Element pipelineEl=doc.createElement(IngestModuleLoader.XmlPipelineRaw.XML_PIPELINE_EL); pipelineEl.setAttribute(IngestModuleLoader.XmlPipelineRaw.XML_PIPELINE_TYPE_ATTR,rawP.type); rootEl.appendChild(pipelineEl); for ( IngestModuleLoader.XmlModuleRaw rawM : rawP.modules) { Element moduleEl=doc.createElement(IngestModuleLoader.XmlModuleRaw.XML_MODULE_EL); moduleEl.setAttribute(IngestModuleLoader.XmlModuleRaw.XML_MODULE_LOC_ATTR,rawM.location); moduleEl.setAttribute(IngestModuleLoader.XmlModuleRaw.XML_MODULE_TYPE_ATTR,rawM.type); moduleEl.setAttribute(IngestModuleLoader.XmlModuleRaw.XML_MODULE_ORDER_ATTR,Integer.toString(rawM.order)); moduleEl.setAttribute(IngestModuleLoader.XmlModuleRaw.XML_MODULE_TYPE_ATTR,rawM.type); pipelineEl.appendChild(moduleEl); } } XMLUtil.saveDoc(IngestModuleLoader.class,absFilePath,ENCODING,doc); logger.log(Level.INFO,"Pipeline configuration saved to: " + this.absFilePath); } catch ( ParserConfigurationException e) { logger.log(Level.SEVERE,"Error saving pipeline config XML: can't initialize parser.",e); } }
Example 18
From project aws-toolkit-for-eclipse, under directory /com.amazonaws.eclipse.core/src/com/amazonaws/eclipse/core/regions/.
Source file: RegionMetadataParser.java

/** * Parses the specified input stream and returns a list of the regions declared in it. * @param input The stream containing the region metadata to parse. * @return The list of parsed regions. */ public List<Region> parseRegionMetadata(InputStream input){ Document document; try { DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder=factory.newDocumentBuilder(); document=documentBuilder.parse(input); } catch ( Exception e) { throw new RuntimeException("Unable to parse region metadata file: " + e.getMessage(),e); } NodeList regionNodes=document.getElementsByTagName(REGION_TAG); List<Region> regions=new ArrayList<Region>(); for (int i=0; i < regionNodes.getLength(); i++) { Node node=regionNodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element=(Element)node; regions.add(parseRegionElement(element)); } } return regions; }
Example 19
From project azure-sdk-for-java-samples, under directory /WAAD.WebSSO.JAVA/java/code/libraries/waad-federation/src/main/java/com/microsoft/samples/federation/.
Source file: SamlTokenValidator.java

private static SignableSAMLObject getSamlTokenFromRstr(String rstr) throws ParserConfigurationException, SAXException, IOException, UnmarshallingException, FederationException { Document document=getDocument(rstr); String xpath="//*[local-name() = 'Assertion']"; NodeList nodes=null; try { nodes=org.apache.xpath.XPathAPI.selectNodeList(document,xpath); } catch ( TransformerException e) { e.printStackTrace(); } if (nodes.getLength() == 0) { throw new FederationException("SAML token was not found"); } Element samlTokenElement=(Element)nodes.item(0); Unmarshaller unmarshaller=Configuration.getUnmarshallerFactory().getUnmarshaller(samlTokenElement); SignableSAMLObject samlToken=(SignableSAMLObject)unmarshaller.unmarshall(samlTokenElement); return samlToken; }
Example 20
From project b3log-latke, under directory /latke/src/main/java/org/b3log/latke/cron/.
Source file: CronService.java

/** * Loads cron.xml. */ private static void loadCronXML(){ final String webRoot=AbstractServletListener.getWebRoot(); final File cronXML=new File(webRoot + File.separator + "WEB-INF"+ File.separator+ "cron.xml"); if (!cronXML.exists()) { LOGGER.log(Level.INFO,"Not found cron.xml, no cron jobs need to schedule"); return; } final DocumentBuilderFactory documentBuilderFactory=DocumentBuilderFactory.newInstance(); try { final DocumentBuilder documentBuilder=documentBuilderFactory.newDocumentBuilder(); final Document document=documentBuilder.parse(cronXML); final Element root=document.getDocumentElement(); root.normalize(); final NodeList crons=root.getElementsByTagName("cron"); LOGGER.log(Level.CONFIG,"Reading cron jobs: "); for (int i=0; i < crons.getLength(); i++) { final Element cronElement=(Element)crons.item(i); final Element urlElement=(Element)cronElement.getElementsByTagName("url").item(0); final Element descriptionElement=(Element)cronElement.getElementsByTagName("description").item(0); final Element scheduleElement=(Element)cronElement.getElementsByTagName("schedule").item(0); final String url=urlElement.getTextContent(); final String description=descriptionElement.getTextContent(); final String schedule=scheduleElement.getTextContent(); LOGGER.log(Level.CONFIG,"Cron[url={0}, description={1}, schedule={2}]",new Object[]{url,description,schedule}); CRONS.add(new Cron(url,description,schedule)); } } catch ( final Exception e) { LOGGER.log(Level.SEVERE,"Reads cron.xml failed",e); throw new RuntimeException(e); } }
Example 21
From project bbb-java, under directory /src/main/java/org/mconf/bbb/api/.
Source file: JoinedMeeting.java

public void parse(String str) throws UnsupportedEncodingException, SAXException, IOException, ParserConfigurationException { DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance(); DocumentBuilder db=dbf.newDocumentBuilder(); Document doc=db.parse(new ByteArrayInputStream(str.getBytes("UTF-8"))); doc.getDocumentElement().normalize(); Element nodeResponse=(Element)doc.getElementsByTagName("response").item(0); returncode=ParserUtils.getNodeValue(nodeResponse,"returncode"); if (returncode.equals("SUCCESS")) { fullname=ParserUtils.getNodeValue(nodeResponse,"fullname"); confname=ParserUtils.getNodeValue(nodeResponse,"confname"); meetingID=ParserUtils.getNodeValue(nodeResponse,"meetingID"); externUserID=ParserUtils.getNodeValue(nodeResponse,"externUserID"); role=ParserUtils.getNodeValue(nodeResponse,"role"); conference=ParserUtils.getNodeValue(nodeResponse,"conference"); room=ParserUtils.getNodeValue(nodeResponse,"room"); voicebridge=ParserUtils.getNodeValue(nodeResponse,"voicebridge"); webvoiceconf=ParserUtils.getNodeValue(nodeResponse,"webvoiceconf"); mode=ParserUtils.getNodeValue(nodeResponse,"mode"); record=ParserUtils.getNodeValue(nodeResponse,"record"); welcome=ParserUtils.getNodeValue(nodeResponse,"welcome"); server=ParserUtils.getNodeValue(nodeResponse,"server"); } else { message=ParserUtils.getNodeValue(nodeResponse,"message"); } }
Example 22
From project bioclipse.seneca, under directory /plugins/net.bioclipse.seneca/src/org/openscience/cdk/structgen/pubchem/.
Source file: PubchemStructureGenerator.java

private final void initRefreshRequestDocument() throws ParserConfigurationException { DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance(); DocumentBuilder builder=factory.newDocumentBuilder(); org.w3c.dom.Document doc=builder.newDocument(); String[] tagNames=new String[]{"PCT-Data_input","PCT-InputData","PCT-InputData_request","PCT-Request"}; doc.appendChild(doc.createElement("PCT-Data")); Element element=doc.getDocumentElement(); for (int i=0; i < tagNames.length; i++) { String tagname=tagNames[i]; Element child=doc.createElement(tagname); element.appendChild(child); element=child; } Element reqid=doc.createElement("PCT-Request_reqid"); reqid.appendChild(doc.createTextNode(this.getRequestID())); Element type=doc.createElement("PCT-Request_type"); type.setAttribute("value","status"); element.appendChild(reqid); element.appendChild(type); this.requestDocument=doc; }
Example 23
From project bioclipse.speclipse, under directory /plugins/net.bioclipse.nmrshiftdb/src/net/bioclipse/nmrshiftdb/business/.
Source file: NmrshiftdbManager.java

public String getSpectrumTypes(String serverurl) throws BioclipseException { try { Options opts=new Options(new String[0]); opts.setDefaultURL(serverurl + "/services/NMRShiftDB"); Service service=new Service(); Call call=(Call)service.createCall(); call.setOperationName("getSpectrumTypes"); call.setTargetEndpointAddress(new URL(opts.getURL())); DocumentBuilder builder; builder=DocumentBuilderFactory.newInstance().newDocumentBuilder(); SOAPBodyElement[] input=new SOAPBodyElement[1]; Document doc=builder.newDocument(); Element cdataElem; cdataElem=doc.createElementNS(opts.getURL(),"getSpectrumTypes"); input[0]=new SOAPBodyElement(cdataElem); Vector elems=(Vector)call.invoke(input); SOAPBodyElement elem=null; Element e=null; elem=(SOAPBodyElement)elems.get(0); e=elem.getAsDOM(); return e.getFirstChild().getTextContent(); } catch ( Exception ex) { throw new BioclipseException(ex.getMessage()); } }
Example 24
From project bam, under directory /release/jbossas/tests/activity-management/bean-service/src/main/java/org/overlord/bam/tests/actmgmt/jbossas/beanservice/.
Source file: Transformers.java

/** * Returns the text value of a child node of parent. */ private String getElementValue(Element parent,String elementName){ String value=null; NodeList nodes=parent.getElementsByTagName(elementName); if (nodes.getLength() > 0) { value=nodes.item(0).getChildNodes().item(0).getNodeValue(); } return value; }
Example 25
From project banshun, under directory /banshun/core/src/main/java/com/griddynamics/banshun/xml/.
Source file: NestedBeanDefinitionParser.java

@Override protected String getBeanClassName(Element element){ String localName=element.getLocalName(); if (EXPORT.equals(localName)) { return Void.class.getCanonicalName(); } else if (IMPORT.equals(localName)) { return element.getAttribute(INTERFACE); } throw new IllegalStateException("Unknown element '" + localName + "'"); }
Example 26
From project blacktie, under directory /blacktie-admin-services/src/main/java/org/jboss/narayana/blacktie/administration/.
Source file: BlacktieStompAdministrationService.java

Element stringToElement(String s) throws Exception { StringReader sreader=new StringReader(s); DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance(); DocumentBuilder parser=factory.newDocumentBuilder(); Document doc=parser.parse(new InputSource(sreader)); return doc.getDocumentElement(); }