List of usage examples for org.w3c.dom Document getDocumentElement
public Element getDocumentElement();
From source file:de.itomig.itoplib.GetItopData.java
private static ArrayList<ItopTicket> parseTicketDoc(Document doc) { // assemble new ArrayList of tickets. tickets.clear();/*from w ww . jav a 2 s . c o m*/ Element root = doc.getDocumentElement(); // look for UserRequest NodeList items = root.getElementsByTagName("UserRequest"); for (int i = 0; i < items.getLength(); i++) { tickets.add(parseTicketNode("UserRequest", items.item(i))); } // look for Incident items = root.getElementsByTagName("Incident"); for (int i = 0; i < items.getLength(); i++) { tickets.add(parseTicketNode("Incident", items.item(i))); } return tickets; // UserRequests and Incidents }
From source file:edu.cornell.mannlib.semservices.util.XMLUtils.java
/** * @param doc (either a Document or a Node) * @param expression//from w w w . j a va 2s .co m * @return string contents */ public static Node getNodeWithXpath(Object obj, String expression) { Object root = null; if (obj instanceof Document) { Document doc = (Document) obj; root = doc.getDocumentElement(); } else { root = (Node) obj; } XPath xpath = XPathFactory.newInstance().newXPath(); xpath.setNamespaceContext(new MetadataNamespaceContext()); Node result = null; try { result = ((Node) xpath.evaluate(expression, root, XPathConstants.NODE)); return result; } catch (XPathExpressionException e) { logger.error("XPathExpressionException ", e); return null; } }
From source file:com.basp.trabajo_al_minuto.model.business.BusinessUtils.java
public static Document normalizeDocument(InputSource inputSource) throws BusinessException { try {/*from w w w . jav a 2s .co m*/ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.parse(inputSource); document.getDocumentElement().normalize(); return document; } catch (SAXException | IOException | ParserConfigurationException ex) { Logger.getLogger(BusinessUtils.class.getName()).log(Level.SEVERE, "BusinessUtils.normalizeDocument Exception", ex); throw new BusinessException(ex); } }
From source file:applab.search.client.JsonSimpleParser.java
static String getKeywordsVersion(Document document) { Element rootNode = document.getDocumentElement(); if (rootNode != null) { String version = rootNode.getAttribute(VERSION_ATTRIBUTE_NAME); if (version.length() > 0) { return version; }//from www . j a v a2 s . c o m } return ""; }
From source file:es.usc.citius.composit.transformer.wsc.wscxml.WSCTransformer.java
public static URL obtainXmlBaseUri(InputStream owlStream) throws IOException, XPathExpressionException, ParserConfigurationException, SAXException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); // Detect namespaces dbf.setNamespaceAware(true);/*from w w w. j ava 2 s. c om*/ DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.parse(owlStream); // Obtain the document element where the xml:base is Element rootElement = document.getDocumentElement(); String baseUri = rootElement.getAttribute("xml:base"); return new URL(baseUri); }
From source file:net.vexelon.bgrates.Utils.java
/** * Serialize a Root element and all it's descendants * @param document - org.w3c.dom Xml Document * @param serializer/* ww w . jav a 2 s . co m*/ * @throws Exception */ private static void serializeXml(Document document, XmlSerializer serializer) throws Exception { serializer.startDocument("UTF-8", true); document.getDocumentElement().normalize(); serializeXmlElement(document, serializer); serializer.endDocument(); }
From source file:fll.xml.XMLUtils.java
/** * Find a subjective category by name.//from w ww .ja va 2 s . c o m * * @param challengeDocument the document to look in * @param name the name to look for * @return the element or null if one is not found */ public static Element getSubjectiveCategoryByName(final Document challengeDocument, final String name) { for (final Element categoryElement : new NodelistElementCollectionAdapter( challengeDocument.getDocumentElement().getElementsByTagName("subjectiveCategory"))) { final String categoryName = categoryElement.getAttribute("name"); if (categoryName.equals(name)) { return categoryElement; } } return null; }
From source file:Main.java
/** * Counts the elements which results from the xpath expression. * //w w w . j a v a 2 s . co m * @param document the xml document. * @param xpath the expression * @param message The assert message. * @return Returns -1 if no element was found. */ public static int count(String message, Document document, String xpath) throws XPathExpressionException { XPathExpression expression = EXPRESSIONS.get(xpath); NodeList list = null; if (expression == null) { expression = XPathFactory.newInstance().newXPath().compile(xpath); EXPRESSIONS.put(xpath, expression); } if ((list = (NodeList) expression.evaluate(document.getDocumentElement(), XPathConstants.NODESET)) != null) { return list.getLength(); } return -1; }
From source file:Main.java
private static Document documentFromSoapBody(SOAPBodyElement element, HashMap<String, String> namespaceDeclarations) throws ParserConfigurationException { Document document = dbf.newDocumentBuilder().newDocument(); Node node = document.importNode(element, true); document.appendChild(node);/*from w ww. j a va 2 s .co m*/ for (String prefix : namespaceDeclarations.keySet()) { String uri = namespaceDeclarations.get(prefix); if (node.lookupNamespaceURI(prefix) == null) { document.getDocumentElement().setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:" + prefix, uri); } } return document; }
From source file:DomUtil.java
/** * Creates a new document./*from ww w .jav a2s . c o m*/ * * @param qualifiedName the qualified name of the document type to be * created * @param publicId the external subset public identifier * @param systemId the external subset system identifier * @param namespaceUri the namespace URI of the document element to create */ public static Document createDocument(String qualifiedName, String publicId, String systemId, String namespaceUri) { DOMImplementation dom = DomUtil.getDocumentBuilder().getDOMImplementation(); DocumentType docType = dom.createDocumentType(qualifiedName, publicId, systemId); Document document = dom.createDocument(namespaceUri, qualifiedName, docType); if (namespaceUri != null) { document.getDocumentElement().setAttribute("xmlns", namespaceUri); } return document; }