本文整理汇总了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>");
}
}
}
}
示例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;
}
}
示例3: getElementText
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
public static String getElementText(XMLStreamReader reader) {
try {
return reader.getElementText();
} catch (XMLStreamException e) {
throw wrapException(e);
}
}
示例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;
}
示例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));
}
}
}
示例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));
}
}
}