org.w3c.dom.Document#hasChildNodes ( )源码实例Demo

下面列出了org.w3c.dom.Document#hasChildNodes ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Bats   文件: DTConfiguration.java
public void loadFile(File file, Scope defaultScope) throws IOException, ParserConfigurationException, SAXException, ConfigException
{
  Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file);
  Element documentElement = doc.getDocumentElement();
  if (!documentElement.getNodeName().equals("configuration")) {
    throw new ConfigException("Root element needs to be \"configuration\"");
  }
  if (doc.hasChildNodes()) {
    NodeList propertyNodes = documentElement.getChildNodes();
    for (int i = 0; i < propertyNodes.getLength(); i++) {
      Node propertyNode = propertyNodes.item(i);
      if (propertyNode.getNodeType() == Node.ELEMENT_NODE) {
        if (propertyNode.getNodeName().equals("property")) {
          processPropertyNode((Element)propertyNode, defaultScope);
        } else {
          LOG.warn("Ignoring unknown element {}", propertyNode.getNodeName());
        }
      }
    }
  }
}
 
源代码2 项目: attic-apex-core   文件: DTConfiguration.java
public void loadFile(File file, Scope defaultScope) throws IOException, ParserConfigurationException, SAXException, ConfigException
{
  Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file);
  Element documentElement = doc.getDocumentElement();
  if (!documentElement.getNodeName().equals("configuration")) {
    throw new ConfigException("Root element needs to be \"configuration\"");
  }
  if (doc.hasChildNodes()) {
    NodeList propertyNodes = documentElement.getChildNodes();
    for (int i = 0; i < propertyNodes.getLength(); i++) {
      Node propertyNode = propertyNodes.item(i);
      if (propertyNode.getNodeType() == Node.ELEMENT_NODE) {
        if (propertyNode.getNodeName().equals("property")) {
          processPropertyNode((Element)propertyNode, defaultScope);
        } else {
          LOG.warn("Ignoring unknown element {}", propertyNode.getNodeName());
        }
      }
    }
  }
}
 
源代码3 项目: oxTrust   文件: BuildVersionService.java
@PostConstruct
public void initalize() {
	try (InputStream is = getClass().getResourceAsStream("/META-INF/beans.xml")) {
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		DocumentBuilder dBuilder = factory.newDocumentBuilder();
           Document doc = dBuilder.parse(is);
		doc.getDocumentElement().normalize();
		log.info("Root element :" + doc.getDocumentElement().getNodeName());
		NodeList nList = doc.getElementsByTagName("bean");

		if (doc.hasChildNodes()) {
			readBuildDetails(nList);
		}
	} catch (Exception ex) {
		log.error("Failed to obtain build version", ex);
	}

}
 
源代码4 项目: EpubParser   文件: Reader.java
private void parseContainerXml(DocumentBuilder docBuilder, Document document, ZipFile epubFile) throws ReadingException {
	if (document.hasChildNodes()) {
		isFoundNeeded = false;
		traverseDocumentNodesAndFillContent(document.getChildNodes(), content.getContainer());
	}

	String opfFilePath = content.getContainer().getFullPathValue();
	ZipEntry opfFileEntry = epubFile.getEntry(opfFilePath);

	if (opfFileEntry == null) {
		for (String entryName : content.getEntryNames()) {
			if (entryName.contains(Constants.EXTENSION_OPF)) {
				opfFileEntry = epubFile.getEntry(entryName);
				break;
			}
		}
	}

	if (opfFileEntry == null) {
		throw new ReadingException(".opf file not found");
	}

	InputStream opfFileInputStream;
	try {
		opfFileInputStream = epubFile.getInputStream(opfFileEntry);
	} catch (IOException e) {
		e.printStackTrace();
		throw new ReadingException("IO error while reading " + Constants.EXTENSION_OPF + " inputstream: " + e.getMessage());
	}

	Document packageDocument = getDocument(docBuilder, opfFileInputStream, Constants.EXTENSION_OPF);
	parseOpfFile(packageDocument, content.getPackage());
}
 
源代码5 项目: gama   文件: DocProcessor.java
protected org.w3c.dom.Element getRootNode(final Document doc) {
	org.w3c.dom.Element root = null;
	if (doc.hasChildNodes()) {
		root = (org.w3c.dom.Element) doc.getElementsByTagName(getRootName()).item(0);
	}
	if (root == null) {
		root = doc.createElement(getRootName());
		doc.appendChild(root);
	}
	return root;
}
 
源代码6 项目: java-client-api   文件: DOMWriter.java
public void serializeDocument(Document document) throws XMLStreamException {
 
  String encoding = document.getInputEncoding();
  String version  = document.getXmlVersion();
  if (encoding != null) {
    serializer.writeStartDocument(encoding, version);
  } else {
    serializer.writeStartDocument(version);
  }
  if (document.hasChildNodes()) {
    serializeNodeList(document.getChildNodes());
  }
  serializer.writeEndDocument();
}
 
源代码7 项目: wildfly-core   文件: CloneProfileTestCase.java
/**
 * Parse root node
 */
private List<String> findProfileSubsystemsInXML(Document doc, String profileName) {
    List<String> output = null;
    if (!doc.hasChildNodes()) {
        return output;
    }
    NodeList nodeList = doc.getChildNodes();
    return findProfileSubsystems(nodeList, profileName);
}
 
源代码8 项目: EpubParser   文件: Reader.java
private void parseOpfFile(Document document, Package pckage) throws ReadingException {
	if (document.hasChildNodes()) {
		isFoundNeeded = false;
		traverseDocumentNodesAndFillContent(document.getChildNodes(), pckage);
	}
}
 
源代码9 项目: EpubParser   文件: Reader.java
private void parseTocFile(Document document, Toc toc) throws ReadingException {
	if (document.hasChildNodes()) {
		isFoundNeeded = false;
		traverseDocumentNodesAndFillContent(document.getChildNodes(), toc);
	}
}
 
源代码10 项目: gama   文件: ExamplesToTests.java
public static void createTests(final ProcessorContext context, final Document doc) {
	if (doc == null || !doc.hasChildNodes()) { return; }
	final Document document = cleanDocumentTest(doc);
	createOperatorsTests(context, document, OPERATORS_TRANSFORMER);
}