本文整理匯總了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));
}
}
}