當前位置: 首頁>>代碼示例>>Java>>正文


Java XMLStreamReader.getElementText方法代碼示例

本文整理匯總了Java中javax.xml.stream.XMLStreamReader.getElementText方法的典型用法代碼示例。如果您正苦於以下問題:Java XMLStreamReader.getElementText方法的具體用法?Java XMLStreamReader.getElementText怎麽用?Java XMLStreamReader.getElementText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.xml.stream.XMLStreamReader的用法示例。


在下文中一共展示了XMLStreamReader.getElementText方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSwitchXMLVersions

import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
/**
 * Verifies that after switching to a different XML Version (1.1), the parser
 * is initialized properly (the listener was not registered in this case).
 *
 * @param path the path to XML source
 * @throws Exception
 */
@Test(dataProvider = "getPaths")
public void testSwitchXMLVersions(String path) throws Exception {
    XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
    xmlInputFactory.setProperty("javax.xml.stream.isCoalescing", true);
    XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(
            this.getClass().getResourceAsStream(path));

    while (xmlStreamReader.hasNext()) {
        int event = xmlStreamReader.next();
        if (event == XMLStreamConstants.START_ELEMENT) {
            if (xmlStreamReader.getLocalName().equals("body")) {
                String elementText = xmlStreamReader.getElementText();
                Assert.assertTrue(!elementText.contains("</body>"),
                        "Fail: elementText contains </body>");
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:StreamReaderTest.java

示例2: getStringContent

import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
public String getStringContent() {
    try {
        XMLStreamReader xsr = readHeader();
        xsr.nextTag();
        return xsr.getElementText();
    } catch (XMLStreamException e) {
        return null;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:10,代碼來源:AbstractHeaderImpl.java

示例3: getElementText

import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
public static String getElementText(XMLStreamReader reader) {
    try {
        return reader.getElementText();
    } catch (XMLStreamException e) {
        throw wrapException(e);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:8,代碼來源:XMLStreamReaderUtil.java

示例4: bindingOperationElements

import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
@Override
public boolean bindingOperationElements(EditableWSDLBoundOperation operation, XMLStreamReader reader) {
    EditableWSDLBoundOperation edit = (EditableWSDLBoundOperation) operation;

    QName anon = reader.getName();
    if (anon.equals(AddressingVersion.W3C.wsdlAnonymousTag)) {
        try {
            String value = reader.getElementText();
            if (value == null || value.trim().equals("")) {
                throw new WebServiceException("Null values not permitted in wsaw:Anonymous.");
                // TODO: throw exception only if wsdl:required=true
                // TODO: is this the right exception ?
            } else if (value.equals("optional")) {
                edit.setAnonymous(ANONYMOUS.optional);
            } else if (value.equals("required")) {
                edit.setAnonymous(ANONYMOUS.required);
            } else if (value.equals("prohibited")) {
                edit.setAnonymous(ANONYMOUS.prohibited);
            } else {
                throw new WebServiceException("wsaw:Anonymous value \"" + value + "\" not understood.");
                // TODO: throw exception only if wsdl:required=true
                // TODO: is this the right exception ?
            }
        } catch (XMLStreamException e) {
            throw new WebServiceException(e);       // TODO: is this the correct behavior ?
        }

        return true;        // consumed the element
    }

    return false;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:33,代碼來源:W3CAddressingWSDLParserExtension.java

示例5: readNodeData

import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
private void readNodeData(XMLStreamReader xmlReader, Vertex v)
		throws XMLStreamException {
	String key = "", value = "";

	for (int i = 0; i < xmlReader.getAttributeCount(); ++i) {
		String attr = xmlReader.getAttributeLocalName(i);

		if (attr.equalsIgnoreCase(KEY)) {
			key = xmlReader.getAttributeValue(i);
		}
	}

	value = xmlReader.getElementText();
	double x = v.getPosition() != null ? v.getPosition().getX() : 0;
	double y = v.getPosition() != null ? v.getPosition().getY() : 0;
	int r = v.getFillColor().getRed(), g = v.getFillColor().getGreen(), b = v
			.getFillColor().getBlue();

	if (!value.isEmpty()) {
		if (key.equalsIgnoreCase(NODE_LABEL)) {
			v.setLabel(value);
		} else if (key.equalsIgnoreCase(NODE_X)) {
			v.setPosition(Double.parseDouble(value), y);
		} else if (key.equalsIgnoreCase(NODE_Y)) {
			v.setPosition(x, Double.parseDouble(value));
		} else if (key.equalsIgnoreCase(NODE_SIZE)) {
			v.setSize(Double.parseDouble(value));
		} else if (key.equalsIgnoreCase(NODE_R)) {
			r = Integer.parseInt(value);
			v.setFillColor(new Color(r, g, b));
		} else if (key.equalsIgnoreCase(NODE_G)) {
			g = Integer.parseInt(value);
			v.setFillColor(new Color(r, g, b));
		} else if (key.equalsIgnoreCase(NODE_B)) {
			b = Integer.parseInt(value);
			v.setFillColor(new Color(r, g, b));
		}
	}
}
 
開發者ID:dev-cuttlefish,項目名稱:cuttlefish,代碼行數:40,代碼來源:GraphMLImporter.java

示例6: readEdgeData

import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
private void readEdgeData(XMLStreamReader xmlReader, Edge e)
		throws XMLStreamException {
	String key = "", value = "";

	for (int i = 0; i < xmlReader.getAttributeCount(); ++i) {
		String attr = xmlReader.getAttributeLocalName(i);

		if (attr.equalsIgnoreCase(KEY)) {
			key = xmlReader.getAttributeValue(i);
		}
	}

	value = xmlReader.getElementText();
	int r = e.getColor().getRed(), g = e.getColor().getGreen(), b = e
			.getColor().getBlue();

	if (!value.isEmpty()) {
		if (key.equalsIgnoreCase(EDGE_LABEL)) {
			e.setLabel(value);
		} else if (key.equalsIgnoreCase(EDGE_WIDTH)) {
			e.setWidth(Double.parseDouble(value));
		} else if (key.equalsIgnoreCase(EDGE_WEIGHT)) {
			e.setWeight(Double.parseDouble(value));
		} else if (key.equalsIgnoreCase(EDGE_R)) {
			r = Integer.parseInt(value);
			e.setColor(new Color(r, g, b));
		} else if (key.equalsIgnoreCase(EDGE_G)) {
			g = Integer.parseInt(value);
			e.setColor(new Color(r, g, b));
		} else if (key.equalsIgnoreCase(EDGE_B)) {
			b = Integer.parseInt(value);
			e.setColor(new Color(r, g, b));
		}
	}

}
 
開發者ID:dev-cuttlefish,項目名稱:cuttlefish,代碼行數:37,代碼來源:GraphMLImporter.java


注:本文中的javax.xml.stream.XMLStreamReader.getElementText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。