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


Java XMLStreamReader类代码示例

本文整理汇总了Java中javax.xml.stream.XMLStreamReader的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamReader类的具体用法?Java XMLStreamReader怎么用?Java XMLStreamReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


XMLStreamReader类属于javax.xml.stream包,在下文中一共展示了XMLStreamReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processReferenceUri

import javax.xml.stream.XMLStreamReader; //导入依赖的package包/类
private void processReferenceUri(
        final String policyUri,
        final WSDLObject element,
        final XMLStreamReader reader,
        final Map<WSDLObject, Collection<PolicyRecordHandler>> map) {

    if (null == policyUri || policyUri.length() == 0) {
        return;
    }
    if ('#' != policyUri.charAt(0)) { // external uri (already)
        getUnresolvedUris(false).add(policyUri);
    }

    addHandlerToMap(map, element,
            new PolicyRecordHandler(
            HandlerType.PolicyUri,
            SafePolicyReader.relativeToAbsoluteUrl(policyUri, reader.getLocation().getSystemId())));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:PolicyWSDLParserExtension.java

示例2: testNamespaceContext

import javax.xml.stream.XMLStreamReader; //导入依赖的package包/类
@Test
public void testNamespaceContext() {
    is = new java.io.ByteArrayInputStream(getXML().getBytes());
    try {
        XMLStreamReader sr = factory.createFilteredReader(factory.createXMLStreamReader(is), (StreamFilter) filter);
        while (sr.hasNext()) {
            int eventType = sr.next();
            if (eventType == XMLStreamConstants.START_ELEMENT) {
                if (sr.getLocalName().equals(childElement)) {
                    NamespaceContext context = sr.getNamespaceContext();
                    Assert.assertTrue(context.getPrefix(namespaceURIApple).equals(prefixApple));
                }
            }
        }
    } catch (Exception ex) {
        Assert.fail("Exception: " + ex.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:Bug6481678.java

示例3: createFIStreamReader

import javax.xml.stream.XMLStreamReader; //导入依赖的package包/类
/**
 * Returns the FI parser allocated for this thread.
 */
public static XMLStreamReader createFIStreamReader(InputStream in) {
    // Check if compatible implementation of FI was found
    if (FastInfosetReflection.fiStAXDocumentParser_new == null) {
        throw new XMLReaderException("fastinfoset.noImplementation");
    }

    try {
        // Do not use StAX pluggable layer for FI
        Object sdp = FastInfosetReflection.fiStAXDocumentParser_new.newInstance();
        FastInfosetReflection.fiStAXDocumentParser_setStringInterning.invoke(sdp, Boolean.TRUE);
        FastInfosetReflection.fiStAXDocumentParser_setInputStream.invoke(sdp, in);
        return (XMLStreamReader) sdp;
    } catch (Exception e) {
        throw new XMLStreamReaderException(e);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:FastInfosetUtil.java

示例4: create

import javax.xml.stream.XMLStreamReader; //导入依赖的package包/类
/**
 * Creates a {@link SDDocumentSource} from {@link XMLStreamBuffer}.
 */
public static SDDocumentSource create(final URL systemId, final XMLStreamBuffer xsb) {
    return new SDDocumentSource() {
        public XMLStreamReader read(XMLInputFactory xif) throws XMLStreamException {
            return xsb.readAsXMLStreamReader();
        }

        public XMLStreamReader read() throws XMLStreamException {
            return xsb.readAsXMLStreamReader();
        }

        public URL getSystemId() {
            return systemId;
        }
    };
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:SDDocumentSource.java

示例5: testChildElementNamespace

import javax.xml.stream.XMLStreamReader; //导入依赖的package包/类
@Test
public void testChildElementNamespace() {
    is = new java.io.ByteArrayInputStream(getXML().getBytes());
    try {
        XMLStreamReader sr = factory.createFilteredReader(factory.createXMLStreamReader(is), (StreamFilter) filter);
        while (sr.hasNext()) {
            int eventType = sr.next();
            if (eventType == XMLStreamConstants.START_ELEMENT) {
                if (sr.getLocalName().equals(childElement)) {
                    QName qname = sr.getName();
                    Assert.assertTrue(qname.getPrefix().equals(prefixApple) && qname.getNamespaceURI().equals(namespaceURIApple)
                            && qname.getLocalPart().equals(childElement));
                }
            }
        }
    } catch (Exception ex) {
        Assert.fail("Exception: " + ex.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:Bug6481678.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: readResponse

import javax.xml.stream.XMLStreamReader; //导入依赖的package包/类
final Object readResponse(Object[] args, XMLStreamReader r, AttachmentSet att) throws JAXBException {
    Object obj;
    AttachmentUnmarshallerImpl au = (att != null)?new AttachmentUnmarshallerImpl(att):null;
    if (bridge instanceof RepeatedElementBridge) {
        RepeatedElementBridge rbridge = (RepeatedElementBridge)bridge;
        ArrayList list = new ArrayList();
        QName name = r.getName();
        while (r.getEventType()==XMLStreamReader.START_ELEMENT && name.equals(r.getName())) {
            list.add(rbridge.unmarshal(r, au));
            XMLStreamReaderUtil.toNextTag(r, name);
        }
        obj = rbridge.collectionHandler().convert(list);
    } else {
        obj = bridge.unmarshal(r, au);
    }
    return setter.put(obj,args);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:ResponseBuilder.java

示例8: 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

示例9: testDefaultAttrNS

import javax.xml.stream.XMLStreamReader; //导入依赖的package包/类
@Test
public void testDefaultAttrNS() {
    XMLInputFactory ifac = XMLInputFactory.newInstance();

    try {
        XMLStreamReader re = ifac.createXMLStreamReader(getClass().getResource(INPUT_FILE1).toExternalForm(),
                this.getClass().getResourceAsStream(INPUT_FILE1));
        while (re.hasNext()) {
            int event = re.next();
            if (event == XMLStreamConstants.START_ELEMENT) {
                // System.out.println("#attrs = " + re.getAttributeCount());
                Assert.assertTrue(re.getAttributeCount() == 2);
                // This works if "" is replaced by null too
                // System.out.println("attr1 = " + re.getAttributeValue("",
                // "attr1"));
                Assert.assertTrue(re.getAttributeValue("", "attr1").equals("pass"));
            }
        }
        re.close();
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Exception occured: " + e.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:Jsr173MR1Req8Test.java

示例10: testNamespaceContext

import javax.xml.stream.XMLStreamReader; //导入依赖的package包/类
@Test
public void testNamespaceContext() {
    try {
        XMLInputFactory xif = XMLInputFactory.newInstance();
        xif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
        InputStream is = new java.io.ByteArrayInputStream(getXML().getBytes());
        XMLStreamReader sr = xif.createXMLStreamReader(is);
        while (sr.hasNext()) {
            int eventType = sr.next();
            if (eventType == XMLStreamConstants.START_ELEMENT) {
                if (sr.getLocalName().equals(childElement)) {
                    NamespaceContext context = sr.getNamespaceContext();
                    Assert.assertTrue(context.getPrefix(namespaceURI).equals(prefix));
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:NamespaceTest.java

示例11: getXMLStreamReader

import javax.xml.stream.XMLStreamReader; //导入依赖的package包/类
private XMLStreamReader getXMLStreamReader(InputStream in) {
    // If the _retainState is true (FI stateful) then pick up Codec assiciated XMLStreamReader
    if (_retainState) {
        if (_statefulParser != null) {
            _statefulParser.setInputStream(in);
            return _statefulParser;
        } else {
            return _statefulParser = FastInfosetCodec.createNewStreamReader(in, _retainState);
        }
    }

    // Otherwise thread assiciated XMLStreamReader
    return READER_FACTORY.doCreate(null, in, false);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:15,代码来源:FastInfosetStreamSOAPCodec.java

示例12: startElement

import javax.xml.stream.XMLStreamReader; //导入依赖的package包/类
/**
 * Utility to use when we meet a startElement in the CIM XML Document.
 * Only the startElement that contains the CIMURI is used.
 *
 * @param xmlsr
 *            The XMLStreamReader used to read the CIM XML Document
 */
public void startElement(final XMLStreamReader xmlsr) {

    // if null, the element is not interpreted

    // We search for a <cim:...> element or for the <md:Model.profile> element
    if(xmlsr.getPrefix().equals("cim")) {
        hasGoodVersion = (xmlsr.getNamespaceURI().equals(CIMURI.CIMURI));
        done = true;
    }
    else if(xmlsr.getPrefix().equals("md") && xmlsr.getName().equals("Model.profile")){
        profileElement = true;
    }

}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:22,代码来源:CIMProgressiveParser.java

示例13: messageElements

import javax.xml.stream.XMLStreamReader; //导入依赖的package包/类
public boolean messageElements(EditableWSDLMessage msg, XMLStreamReader reader) {
    for (WSDLParserExtension e : extensions) {
        if (e.messageElements(msg, reader)) {
            return true;
        }
    }
    XMLStreamReaderUtil.skipElement(reader);
    return true;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:WSDLParserExtensionFacade.java

示例14: unmarshal

import javax.xml.stream.XMLStreamReader; //导入依赖的package包/类
@Override
public <T> JAXBElement<T> unmarshal(XMLStreamReader reader, Class<T> expectedType) throws JAXBException {
    if (expectedType==null) {
        throw new IllegalArgumentException();
    }
    return (JAXBElement)unmarshal0(reader,getBeanInfo(expectedType));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:UnmarshallerImpl.java

示例15: addAttributes

import javax.xml.stream.XMLStreamReader; //导入依赖的package包/类
protected void addAttributes(StartElementEvent event,XMLStreamReader streamReader){
    AttributeBase attr = null;
    for(int i=0; i<streamReader.getAttributeCount() ;i++){
        attr = (AttributeBase)factory.createAttribute(streamReader.getAttributeName(i),
                                streamReader.getAttributeValue(i));
        attr.setAttributeType(streamReader.getAttributeType(i));
        attr.setSpecified(streamReader.isAttributeSpecified(i));
        event.addAttribute(attr);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:StAXEventAllocatorBase.java


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