本文整理匯總了Java中javax.xml.stream.XMLStreamReader.nextTag方法的典型用法代碼示例。如果您正苦於以下問題:Java XMLStreamReader.nextTag方法的具體用法?Java XMLStreamReader.nextTag怎麽用?Java XMLStreamReader.nextTag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.stream.XMLStreamReader
的用法示例。
在下文中一共展示了XMLStreamReader.nextTag方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readFeatureMap
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
/**
* Processes a GateDocumentFeatures or Annotation element to build a
* feature map. The element is expected to contain Feature children,
* each with a Name and Value. The reader will be returned positioned
* on the closing GateDocumentFeatures or Annotation tag.
*
* @throws XMLStreamException
*/
public static FeatureMap readFeatureMap(XMLStreamReader xsr)
throws XMLStreamException {
FeatureMap fm = Factory.newFeatureMap();
while(xsr.nextTag() == XMLStreamConstants.START_ELEMENT) {
xsr.require(XMLStreamConstants.START_ELEMENT, null, "Feature");
Object featureName = null;
Object featureValue = null;
while(xsr.nextTag() == XMLStreamConstants.START_ELEMENT) {
if("Name".equals(xsr.getLocalName())) {
featureName = readFeatureNameOrValue(xsr);
}
else if("Value".equals(xsr.getLocalName())) {
featureValue = readFeatureNameOrValue(xsr);
}
else {
throw new XMLStreamException("Feature element should contain "
+ "only Name and Value children", xsr.getLocation());
}
}
fm.put(featureName, featureValue);
}
return fm;
}
示例2: readXcesFeatureMap
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
/**
* Processes a struct element to build a feature map. The element is
* expected to contain feat children, each with name and value
* attributes. The reader will be returned positioned on the closing
* struct tag.
*
* @throws XMLStreamException
*/
public static FeatureMap readXcesFeatureMap(XMLStreamReader xsr)
throws XMLStreamException {
FeatureMap fm = Factory.newFeatureMap();
while(xsr.nextTag() == XMLStreamConstants.START_ELEMENT) {
xsr.require(XMLStreamConstants.START_ELEMENT, XCES_NAMESPACE, "feat");
String featureName = xsr.getAttributeValue(null, "name");
Object featureValue = xsr.getAttributeValue(null, "value");
fm.put(featureName, featureValue);
// read the (possibly virtual) closing tag of the feat element
xsr.nextTag();
xsr.require(XMLStreamConstants.END_ELEMENT, XCES_NAMESPACE, "feat");
}
return fm;
}
示例3: parseAttributes
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
/**
* We don't really expect this to be used, but just to satisfy
* the {@link Header} contract.
*
* So this is rather slow.
*/
private void parseAttributes() {
try {
XMLStreamReader reader = readHeader();
reader.nextTag(); // move to the first element, which is the header element
attributes = new FinalArrayList<Attribute>();
boolean refParamAttrWritten = false;
for (int i = 0; i < reader.getAttributeCount(); i++) {
final String attrLocalName = reader.getAttributeLocalName(i);
final String namespaceURI = reader.getAttributeNamespace(i);
final String value = reader.getAttributeValue(i);
if (namespaceURI.equals(AddressingVersion.W3C.nsUri)&& attrLocalName.equals("IS_REFERENCE_PARAMETER")) {
refParamAttrWritten = true;
}
attributes.add(new Attribute(namespaceURI,attrLocalName,value));
}
// we are adding one more attribute "wsa:IsReferenceParameter", if its not alrady there
if (!refParamAttrWritten) {
attributes.add(new Attribute(AddressingVersion.W3C.nsUri,IS_REFERENCE_PARAMETER,TRUE_VALUE));
}
} catch (XMLStreamException e) {
throw new WebServiceException("Unable to read the attributes for {"+nsUri+"}"+localName+" header",e);
}
}
示例4: readWrappedRequest
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
protected void readWrappedRequest(Message msg, Object[] args) throws JAXBException, XMLStreamException {
if (!msg.hasPayload()) {
throw new WebServiceException("No payload. Expecting payload with "+wrapperName+" element");
}
XMLStreamReader reader = msg.readPayload();
XMLStreamReaderUtil.verifyTag(reader,wrapperName);
reader.nextTag();
while(reader.getEventType()==XMLStreamReader.START_ELEMENT) {
// TODO: QName has a performance issue
QName name = reader.getName();
WrappedPartBuilder part = wrappedParts.get(name);
if(part==null) {
// no corresponding part found. ignore
XMLStreamReaderUtil.skipElement(reader);
reader.nextTag();
} else {
part.readRequest(args,reader, msg.getAttachments());
}
XMLStreamReaderUtil.toNextTag(reader, name);
}
// we are done with the body
reader.close();
XMLStreamReaderFactory.recycle(reader);
}
示例5: parseObject
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
private T parseObject(final Object sourceOrStream) throws ParseException {
try {
final XMLStreamReader xmlStreamReader;
if (sourceOrStream instanceof InputStream) {
xmlStreamReader = FACTORY.createXMLStreamReader((InputStream) sourceOrStream);
} else if (sourceOrStream instanceof Source) {
xmlStreamReader = FACTORY.createXMLStreamReader((Source) sourceOrStream);
} else {
throw new IllegalArgumentException("Verwacht Source of InputStream");
}
// positioneer de cursor van de reader op het eerste element
xmlStreamReader.nextTag();
return parse(xmlStreamReader);
} catch (XMLStreamException e) {
throw new ParseException("Fout bij het maken van een XmlStreamReader.", e);
}
}
示例6: testStAXSourceWEmptyNS
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
/**
* @bug 8152530
* Verifies that StAXSource handles empty namespace properly. NPE was thrown
* before the fix.
* @throws Exception if the test fails
*/
@Test
public final void testStAXSourceWEmptyNS() throws Exception {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<EntityList>\n"
+ " <Entity xmlns=\"\">\n"
+ " </Entity>\n"
+ " <Entity xmlns=\"\">\n"
+ " </Entity>\n"
+ "</EntityList> ";
XMLInputFactory xif = XMLInputFactory.newInstance();
XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(xml));
xsr.nextTag();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
while (xsr.nextTag() == XMLStreamConstants.START_ELEMENT && xsr.getLocalName().equals("Entity")) {
StringWriter stringResult = new StringWriter();
t.transform(new StAXSource(xsr), new StreamResult(stringResult));
System.out.println("result: \n" + stringResult.toString());
}
}
示例7: getStringContent
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
public String getStringContent() {
try {
XMLStreamReader xsr = readHeader();
xsr.nextTag();
return xsr.getElementText();
} catch (XMLStreamException e) {
return null;
}
}
示例8: testSkippingExternalDTD
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
@Test
public void testSkippingExternalDTD() throws Exception {
XMLInputFactory xif = XMLInputFactory.newInstance();
try(
InputStream is= getClass().getResourceAsStream("XMLSchema.xsd");
) {
XMLStreamReader reader = xif.createXMLStreamReader(getClass().getResource("XMLSchema.xsd").getFile(), is);
int e;
while ((e = reader.next()) == XMLStreamConstants.COMMENT);
Assert.assertEquals(e, XMLStreamConstants.DTD, "should be DTD");
reader.nextTag();
Assert.assertEquals(reader.getLocalName(), "schema", "next tag should be schema");
}
}
示例9: readRelationSet
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
public static void readRelationSet(XMLStreamReader xsr,
RelationSet relations, Set<Integer> allAnnotIds)
throws XMLStreamException {
while(xsr.nextTag() == XMLStreamConstants.START_ELEMENT) {
xsr.require(XMLStreamConstants.START_ELEMENT, null, "Relation");
String type = xsr.getAttributeValue(null, "Type");
String idString = xsr.getAttributeValue(null, "Id");
String memberString = xsr.getAttributeValue(null, "Members");
if(memberString == null)
throw new XMLStreamException("A relation must have members");
if (type == null)
throw new XMLStreamException("A relation must have a type");
if (idString == null)
throw new XMLStreamException("A relation must have an id");
String[] memberStrings = memberString.split(";");
int[] members = new int[memberStrings.length];
for(int i = 0; i < members.length; ++i) {
members[i] = Integer.parseInt(memberStrings[i]);
}
xsr.nextTag();
xsr.require(XMLStreamConstants.START_ELEMENT, null, "UserData");
// get the string representation of the user data
StringBuilder stringRep = new StringBuilder(1024);
int eventType;
while((eventType = xsr.next()) != XMLStreamConstants.END_ELEMENT) {
switch(eventType) {
case XMLStreamConstants.CHARACTERS:
case XMLStreamConstants.CDATA:
stringRep.append(xsr.getTextCharacters(), xsr.getTextStart(),
xsr.getTextLength());
break;
case XMLStreamConstants.START_ELEMENT:
throw new XMLStreamException("Elements not allowed within "
+ "user data.", xsr.getLocation());
default:
// do nothing - ignore comments, PIs, etc.
}
}
xsr.require(XMLStreamConstants.END_ELEMENT, null, "UserData");
FeatureMap features = readFeatureMap(xsr);
Relation r = new SimpleRelation(Integer.parseInt(idString), type, members);
r.setFeatures(features);
if(stringRep.length() > 0) {
ObjectWrapper wrapper = new ObjectWrapper(stringRep.toString());
r.setUserData(wrapper.getValue());
}
relations.add(r);
}
}