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


Java XMLStreamReader.nextTag方法代码示例

本文整理汇总了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;
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:32,代码来源:DocumentStaxUtils.java

示例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;
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:24,代码来源:DocumentStaxUtils.java

示例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);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:OutboundReferenceParameterHeader.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:EndpointArgumentsBuilder.java

示例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);
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:18,代码来源:AbstractParser.java

示例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());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:StAXSourceTest.java

示例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;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:AbstractHeaderImpl.java

示例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");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:IssueTracker35.java

示例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);
  }
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:61,代码来源:DocumentStaxUtils.java


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