當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。