List of usage examples for org.w3c.dom Document getDocumentElement
public Element getDocumentElement();
From source file:Main.java
/** * * @param xmlContent/*from ww w . j a va 2 s . co m*/ * @param charset * @param attributeName * @param matches * @return * @throws SAXException * @throws IOException * @throws ParserConfigurationException * @throws TransformerException */ public static String addAttribute(String xmlContent, Charset charset, String attributeName, String... matches) throws SAXException, IOException, ParserConfigurationException, TransformerException { Document document = parse(xmlContent, charset); Element element = document.getDocumentElement(); addAttributeLoopElement(element, attributeName, 1, matches); return write(document); }
From source file:com.googlecode.promnetpp.main.Main.java
private static void loadXMLFile() { Logger.getLogger(Main.class.getName()).log(Level.INFO, "Loading " + "configuration from file {0}", configurationFilePath);/*from ww w. j av a2s . c o m*/ File configurationFile = new File(configurationFilePath); assert configurationFile.exists() : "Configuration file " + configurationFilePath + " does not exist!"; Document configurationDocument = Utilities.getDocumentFromFile(configurationFile); configurationDocument.getDocumentElement().normalize(); String expectedRootElementName = "promnetppConfiguration"; String actualRootElementName = configurationDocument.getDocumentElement().getNodeName(); assert expectedRootElementName.equals(actualRootElementName) : "" + "Configuration document " + configurationFilePath + " is" + " malformed! Root element must be " + expectedRootElementName + ". Found: " + actualRootElementName; Options.fromDocument(configurationDocument); }
From source file:Main.java
/** * * @param xmlContent// ww w. j a va2s. co m * @param charset * @param attributeName * @param matches * @return * @throws SAXException * @throws IOException * @throws ParserConfigurationException * @throws TransformerException */ public static String removeAttribute(String xmlContent, Charset charset, String attributeName, String... matches) throws SAXException, IOException, ParserConfigurationException, TransformerException { Document document = parse(xmlContent, charset); Element element = document.getDocumentElement(); removeAttributeLoopElement(element, attributeName, matches); return write(document); }
From source file:com.wso2telco.hub.workflow.extensions.util.WorkflowProperties.java
public static Map<String, String> loadWorkflowPropertiesFromXML() { if (propertiesMap == null) { try {//from w w w. j av a2s . c o m propertiesMap = new HashMap<String, String>(); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); String carbonHome = System.getProperty("carbon.home"); String workflowPropertiesFile = carbonHome + "/repository/conf/" + WORKFLOW_PROPERTIES_XML_FILE; Document document = builder.parse(new File(workflowPropertiesFile)); Element rootElement = document.getDocumentElement(); NodeList nodeList = rootElement.getElementsByTagName("Property"); if (nodeList != null && nodeList.getLength() > 0) { for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); String nodeName = node.getAttributes().getNamedItem("name").getNodeValue(); if (nodeName.equalsIgnoreCase(SERVICE_HOST) || nodeName.equalsIgnoreCase(KEY_WORKFLOW_EMAIL_NOTIFICATION_HOST) || nodeName.equalsIgnoreCase(KEY_WORKFLOW_EMAIL_NOTIFICATION_FROM_ADDRESS) || nodeName.equalsIgnoreCase(KEY_WORKFLOW_EMAIL_NOTIFICATION_FROM_PASSWORD) || nodeName.equalsIgnoreCase(PUBLISHER_ROLE_START_WITH) || nodeName.equalsIgnoreCase(PUBLISHER_ROLE_END_WITH) || nodeName.equalsIgnoreCase(MANDATE_SERVICE_HOST)) { String value = ((Element) node).getTextContent(); propertiesMap.put(nodeName, value); } else { //Not a matching property } } } } catch (Exception e) { String errorMessage = "Error in WorkflowProperties.loadWorkflowPropertiesFromXML"; log.error(errorMessage, e); } } else { //Return already loaded propertiesMap } return propertiesMap; }
From source file:net.mindengine.oculus.frontend.domain.document.testcase.Testcase.java
public static Testcase parse(String xmlData) throws Exception { Testcase testcase = new Testcase(); try {//w w w .j av a 2 s .co m DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder builder = dbf.newDocumentBuilder(); Reader reader = new CharArrayReader(xmlData.toCharArray()); org.w3c.dom.Document doc = builder.parse(new org.xml.sax.InputSource(reader)); Node root = doc.getDocumentElement(); NodeList nodeList = root.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if ("steps".equals(node.getNodeName())) { NodeList stepsList = node.getChildNodes(); for (int j = 0; j < stepsList.getLength(); j++) { Node n = stepsList.item(j); TestcaseStep step = new TestcaseStep(); step.setAction(XmlUtils.getChildNodeText(n, "action")); step.setExpected(XmlUtils.getChildNodeText(n, "expected")); step.setComment(XmlUtils.getChildNodeText(n, "comment")); testcase.steps.add(step); } } } } catch (Exception e) { } return testcase; }
From source file:Main.java
public static void append(Document source, String path, Document target) throws XPathExpressionException, IOException { Element e = target.getDocumentElement(); if (e == null) { e = target.createElement("result"); target.appendChild(e);//ww w. j a v a 2 s .com } append(source.getDocumentElement(), path, e); }
From source file:Main.java
public static boolean validateDocumentByKey(final Document document, Key validatingKey) throws SignatureException { final DOMValidateContext valContext = new DOMValidateContext(validatingKey, getSignatureNode(document.getDocumentElement())); try {// w ww . j a va 2 s . c o m final XMLSignature signature = getXMLSignatureFactory().unmarshalXMLSignature(valContext); return signature.validate(valContext); } catch (final Exception e) { throw new SignatureException("Signature verification error", e); } }
From source file:Main.java
public static void setXsdSchema(Node node, String schemaURL) { Document doc; if (node.getNodeType() != Node.DOCUMENT_NODE) { doc = node.getOwnerDocument();/* w w w. ja va 2 s . c om*/ } else { doc = (Document) node; } Element root = doc.getDocumentElement(); if (schemaURL == null) { root.removeAttribute("xmlns:xsi"); root.removeAttribute("xsi:noNamespaceSchemaLocation"); } else { root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.setAttribute("xsi:noNamespaceSchemaLocation", schemaURL); } }
From source file:Main.java
/** * Get root element from XML String/*from w w w .j av a2s .c o m*/ * * @param arg * XML String * @return Root Element * @throws ParserConfigurationException * @throws SAXException * @throws IOException */ public static Element getDocumentElementFromString(String arg) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory dbf; DocumentBuilder db; Document document; dbf = DocumentBuilderFactory.newInstance(); db = dbf.newDocumentBuilder(); document = db.parse(new InputSource(new StringReader(arg))); Element element = document.getDocumentElement(); return element; }
From source file:com.cuubez.visualizer.processor.ConfigurationProcessor.java
private static boolean isEmpty(final Document document) { if (document == null) { return false; }//from w w w . jav a 2 s.c om if (document.getDocumentElement() == null) { return false; } return true; }