当前位置: 首页>>代码示例>>Java>>正文


Java Element.normalize方法代码示例

本文整理汇总了Java中org.w3c.dom.Element.normalize方法的典型用法代码示例。如果您正苦于以下问题:Java Element.normalize方法的具体用法?Java Element.normalize怎么用?Java Element.normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.w3c.dom.Element的用法示例。


在下文中一共展示了Element.normalize方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: LoadXML

import org.w3c.dom.Element; //导入方法依赖的package包/类
public InfoTable LoadXML(File f) throws IOException, ParserConfigurationException, SAXException {
    File inputFile = new File("src/infotable.xml");
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(inputFile);
    Element root = doc.getDocumentElement();
    root.normalize();
    NodeList namesList = root.getChildNodes();

    ArrayList<String> names = new ArrayList<>();
    ArrayList<String> infos = new ArrayList<>();
    for (int i = 0; i < namesList.getLength(); i++) {
        Node n = namesList.item(i);
        if (n.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }
        Element tableElement = (Element) n;
        String tagName = tableElement.getTagName();
        MainDataEnum e = MainDataEnum.valueOf(tagName);
        names.add(e.getVal());
        infos.add(tableElement.getTextContent());
    }

    InfoTable it = new InfoTable(names, infos);
    return it;
}
 
开发者ID:froehlichA,项目名称:RA-Reader,代码行数:27,代码来源:ReadFromXML.java

示例2: loadSignature

import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
 * Parse and extra type info from method signatures
 * @param element The element to read
 */
private void loadSignature(Element element)
{
    StringBuffer sigtext = new StringBuffer();

    // This coagulates text nodes, not sure if we need to do this?
    element.normalize();

    NodeList nodes = element.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++)
    {
        Node node = nodes.item(i);
        short type = node.getNodeType();
        if (type != Node.TEXT_NODE && type != Node.CDATA_SECTION_NODE)
        {
            log.warn("Ignoring illegal node type: " + type);
            continue;
        }

        sigtext.append(node.getNodeValue());
    }

    SignatureParser sigp = new SignatureParser(converterManager, creatorManager);
    sigp.parse(sigtext.toString());
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:29,代码来源:DwrXmlConfigurator.java

示例3: getPomProperties

import org.w3c.dom.Element; //导入方法依赖的package包/类
private Map<String, String> getPomProperties(Element parentElement) {
    Map<String, String> pomProperties = new HashMap<String, String>();
    Element propsEl = getFirstChildElement(parentElement, PROPERTIES);
    if (propsEl != null) {
        propsEl.normalize();
    }
    for (Element prop : getAllChilds(propsEl)) {
        pomProperties.put(prop.getNodeName(), getTextContent(prop));
    }
    return pomProperties;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:12,代码来源:PomReader.java

示例4: XmlPlatformConfig

import org.w3c.dom.Element; //导入方法依赖的package包/类
public XmlPlatformConfig(FileSystem fileSystem, Path configDir, Path cacheDir, String configName)
        throws IOException, SAXException, ParserConfigurationException {
    super(fileSystem, configDir, cacheDir);

    Path file = configDir.resolve(configName + ".xml");
    if (Files.exists(file)) {
        LOGGER.info("Platform configuration defined by XML file {}", file);
        try (InputStream is = Files.newInputStream(file)) {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = builder.parse(is);
            Element root = doc.getDocumentElement();
            root.normalize();
            NodeList moduleNodes = root.getChildNodes();
            for (int i = 0; i < moduleNodes.getLength(); i++) {
                Node moduleNode = moduleNodes.item(i);
                if (moduleNode.getNodeType() == Node.ELEMENT_NODE) {
                    String moduleName = moduleNode.getLocalName();
                    Map<Object, Object> properties = new HashMap<>();
                    NodeList propertyNodes = moduleNode.getChildNodes();
                    for (int j = 0; j < propertyNodes.getLength(); j++) {
                        Node propertyNode = propertyNodes.item(j);
                        if (propertyNode.getNodeType() == Node.ELEMENT_NODE) {
                            String propertyName = propertyNode.getLocalName();
                            Node child = propertyNode.getFirstChild();
                            String propertyValue = child != null ? child.getTextContent() : "";
                            properties.put(propertyName, propertyValue);
                        }
                    }
                    ((InMemoryModuleConfigContainer) container).getConfigs().put(moduleName, new MapModuleConfig(properties, fileSystem));
                }
            }
        }
    } else {
        LOGGER.info("Platform configuration XML file {} not found", file);
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:39,代码来源:XmlPlatformConfig.java

示例5: loadCronXML

import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
 * Loads cron.xml.
 */
private static void loadCronXML() {
	final File cronXML = Latkes.getWebFile("/WEB-INF/cron.xml");

	if (null == cronXML || !cronXML.exists()) {
		logger.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");

		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();

			CRONS.add(new Cron(url, description, schedule));
		}
	} catch (final Exception e) {
		logger.error("Reads cron.xml failed", e);
		throw new RuntimeException(e);
	}
}
 
开发者ID:daima,项目名称:solo-spring,代码行数:41,代码来源:CronService.java

示例6: testGetChild

import org.w3c.dom.Element; //导入方法依赖的package包/类
@Test
public void testGetChild() throws Exception {
    Document document = createDOMWithNS("ElementSample01.xml");
    Element elemNode = (Element) document.getElementsByTagName("b:aaa").item(0);
    elemNode.normalize();
    Node firstChild = elemNode.getFirstChild();
    Node lastChild = elemNode.getLastChild();
    assertEquals(firstChild.getNodeValue(), "fjfjf");
    assertEquals(lastChild.getNodeValue(), "fjfjf");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:ElementTest.java

示例7: testNormalize

import org.w3c.dom.Element; //导入方法依赖的package包/类
@Test
public void testNormalize() throws Exception {
    Document document = createDOM("Node05.xml");

    Element root = document.getDocumentElement();

    Node node =  document.getElementsByTagName("title").item(0);
    node.appendChild(document.createTextNode("test"));
    root.normalize();
    assertEquals(node.getChildNodes().item(0).getNodeValue(), "Typographytest");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:NodeTest.java

示例8: loadFromXml

import org.w3c.dom.Element; //导入方法依赖的package包/类
private void loadFromXml(Document doc, XMLFormatConfig loadingConfig) throws Exception {
    this.loadingConfig = loadingConfig;
    allSentences = new ArrayList<>();

    Element root = doc.getDocumentElement();
    root.normalize();

    NodeList l = doc.getElementsByTagName(loadingConfig.sentenceNodeName);
    Map<String, Token> tokensToRefIds = new HashMap<>(); //used for startPositionInSentence spanAnnotations
    for (int i = 0; i < l.getLength(); i++) {
        addSentence(new InmemorySentence(l.item(i), tokensToRefIds));
    }

    List<Element> annotationsElems = new ArrayList<>();
    l = doc.getElementsByTagName("GGS:SpanAnnotation");
    for (int i = 0; i < l.getLength(); i++)
        annotationsElems.add((Element) l.item(i));
    l = doc.getElementsByTagName("GGS:Annotation");
    for (int i = 0; i < l.getLength(); i++)
        annotationsElems.add((Element) l.item(i));

    for (Element elem : annotationsElems) {
        SpanAnnotation spanAnnotation = new SpanAnnotation();
        Token startToken = tokensToRefIds.get(elem.getAttribute("GGS:StartTokenRefId"));
        Token endToken = tokensToRefIds.get(elem.getAttribute("GGS:EndTokenRefId"));
        spanAnnotation.setStartTokenIndex(startToken.getTokenIndexInSentence());
        spanAnnotation.setEndTokenIndex(endToken.getTokenIndexInSentence());
        spanAnnotation.setSentence(startToken.getParentSentence());
        spanAnnotation.setName(elem.getAttribute("GGS:Name"));
        for (int j = 0; j < elem.getAttributes().getLength(); j++) {
            Node attr = elem.getAttributes().item(j);
            if (attr.getNodeName().startsWith("GGS:"))
                continue;
            spanAnnotation.features.put(attr.getNodeName(), attr.getNodeValue());
        }
        spanAnnotation.getSentence().getSpanAnnotations().add(spanAnnotation);
        for (int j = startToken.getTokenIndexInSentence(); j < endToken.getTokenIndexInSentence() + 1; j++) {
            startToken.getParentSentence().getToken(j).getParentSpanAnnotations().add(spanAnnotation);
        }
    }
}
 
开发者ID:radsimu,项目名称:UaicNlpToolkit,代码行数:42,代码来源:InmemoryCorpus.java

示例9: main

import org.w3c.dom.Element; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();

    UaicMorphologicalDictionary dic = new UaicMorphologicalDictionary();
    dic.diacriticsPolicy = UaicMorphologicalDictionary.StrippedDiacriticsPolicy.NeverStripped;
    dic.load(new FileInputStream(args[1]));
    PrintWriter pw = new PrintWriter(args[2], "UTF8");
    Set<String> lines = new HashSet<String>();

    Set<String> manualTagset = null;
    PrintWriter invalidReport = new PrintWriter("lexiconExtractionReport.txt");
    System.out.println("Extracting pos lexicon from tb files from " + args[0]);
    Map<String,Integer> invalidCount = new TreeMap<String, Integer>();
    
    if (args[3] != null) {
        manualTagset = CompileUaicMorphologicalDictionary.loadManualTagset(new FileInputStream(args[3]));
        System.out.println("Also validating msd tags and creating report in lexiconExtractionReport.txt");
    }
            
    for (File f : new File(args[0]).listFiles()) {
        Document doc = dBuilder.parse(new FileInputStream(f));
        Element root = doc.getDocumentElement();
        root.normalize();
        NodeList sentsElems = doc.getElementsByTagName("sentence");

        for (int i = 0; i < sentsElems.getLength(); i++) {
            NodeList words = ((Element) sentsElems.item(i)).getElementsByTagName("word");
            for (int k = 0; k < words.getLength(); k++) {
                Element wordElem = (Element) words.item(k);
                String form = wordElem.getAttribute("form").trim();
                String lemma = wordElem.getAttribute("lemma").trim().replaceAll("[~_]", " ");
                String msd = wordElem.getAttribute("postag").trim();

                if (form == null || form.isEmpty() || form.trim().isEmpty() || lemma == null || lemma.isEmpty() || lemma.trim().isEmpty() || msd == null || msd.isEmpty() || msd.trim().isEmpty()) {
                    invalidReport.println(String.format("something wrong in entry: <word id=\"%s\" form=\"%s\" lemma=\"%s\" msd=\"%s\" ...  (%s)", wordElem.getAttribute("id"), form, lemma, msd, f.getName()));
                    continue;
                }
                if (manualTagset != null && !manualTagset.contains(msd)){
                    invalidReport.println(String.format("invalid msd: %s\tLEMMA=%s\tMSD=%s  ...  (%s)", form, lemma, msd, f.getName()));
                    Integer c = invalidCount.get(msd);
                    if (c == null)
                        c = 0;
                    invalidCount.put(msd, ++c);
                }
                
                Set<UaicMorphologicalAnnotation> as = dic.get(form);
                boolean found = false;
                if (as != null) {
                    for (UaicMorphologicalAnnotation a : as) {
                        if (a.getMsd().equals(msd) && UaicMorphologicalDictionary.getCleanedUpWord(a.getLemma()).toLowerCase().equals(lemma.toLowerCase())) {
                            found = true;
                            break;
                        }
                    }
                }
                if (!found) {
                    String line = String.format("%s\tLEMMA=%s\tMSD=%s", form, lemma, msd);
                    if (!lines.contains(line)) {
                        pw.println(line);
                        lines.add(line);
                    }
                }
            }
        }
    }
    
    if (manualTagset != null){
        invalidReport.println("\n============Invalid tags with count==========");
        for (Entry<String, Integer> entry : invalidCount.entrySet()){
            invalidReport.println(entry.getKey() + "\t" + entry.getValue());
        }
    }
    
    invalidReport.close();
    pw.close();
}
 
开发者ID:radsimu,项目名称:UaicNlpToolkit,代码行数:78,代码来源:PrecompileFromCorpus.java


注:本文中的org.w3c.dom.Element.normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。