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


Java XMLStreamReader2类代码示例

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


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

示例1: create

import org.codehaus.stax2.XMLStreamReader2; //导入依赖的package包/类
public void create(NetPlan netPlan, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
	{
		this.mapOldId2Node = new HashMap<Long,Node> ();
		this.mapOldId2Srg = new HashMap<Long,SharedRiskGroup> ();
		this.mapOldId2Layer = new HashMap<Long,NetworkLayer> ();
		this.mapOldId2Link = new HashMap<Long,Link> ();
		this.mapOldId2Demand = new HashMap<Long,Demand> ();
		this.mapOldId2MulticastDemand = new HashMap<Long,MulticastDemand> ();
		this.mapOldId2Route = new HashMap<Long,Route> ();
		this.mapOldId2MulticastTree = new HashMap<Long,MulticastTree> ();
		//this.mapOldId2ProtectionSegment = new HashMap<Long,ProtectionSegment> ();
		this.hasAlreadyReadOneLayer = false;
		parseNetwork(netPlan, xmlStreamReader);

//		System.out.println ("End ReaderNetPlan_v4: " + netPlan + " ----------- ");
		
		if (ErrorHandling.isDebugEnabled()) netPlan.checkCachesConsistency();
	}
 
开发者ID:girtel,项目名称:Net2Plan,代码行数:19,代码来源:ReaderNetPlanN2PVersion_4.java

示例2: create

import org.codehaus.stax2.XMLStreamReader2; //导入依赖的package包/类
@Override
public void create(NetPlan netPlan, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
	this.mapOldId2Node = new HashMap<Long,Node> ();
	this.mapOldId2Srg = new HashMap<Long,SharedRiskGroup> ();
	this.mapOldId2Layer = new HashMap<Long,NetworkLayer> ();
	this.mapOldId2Link = new HashMap<Pair<Long,Long>,Link> ();
	this.mapOldId2Demand = new HashMap<Pair<Long,Long>,Demand> ();
	this.mapOldId2Route = new HashMap<Pair<Long,Long>,Route> ();
	//this.mapOldId2ProtectionSegment = new HashMap<Pair<Long,Long>,ProtectionSegment> ();
	this.hasAlreadyReadOneLayer = false;
	
	parseNetwork(netPlan, xmlStreamReader);
	
	// System.out.println ("netPlan leido: --- " + netPlan + " --- netPlan leido");
	if (ErrorHandling.isDebugEnabled()) netPlan.checkCachesConsistency();

}
 
开发者ID:girtel,项目名称:Net2Plan,代码行数:19,代码来源:ReaderNetPlanN2PVersion_2.java

示例3: testParsingMonograph_idno_shouldWork

import org.codehaus.stax2.XMLStreamReader2; //导入依赖的package包/类
@Test
public void testParsingMonograph_idno_shouldWork() throws Exception {
    InputStream inputStream = this.getClass().getResourceAsStream("/hal-00576900.corpus.tei.xml");
    XMLStreamReader2 reader = (XMLStreamReader2) inputFactory.createXMLStreamReader(inputStream);

    StaxUtils.traverse(reader, target);

    assertThat(publication.getMonograph(), notNullValue());

    Monograph monograph = publication.getMonograph();
    assertThat(monograph.getType(), is("m"));
    assertThat(monograph.getTitle(), is("Accuracy2010"));
    assertThat(target.getCollection().getTitle(), is("Accuracy2010"));
    assertThat(target.getJournal().getTitle(), is(""));

}
 
开发者ID:anHALytics,项目名称:anhalytics-core,代码行数:17,代码来源:PublicationTeiDocumentStaxHandlerTest.java

示例4: testParsingMonogram_meeting_shouldWork

import org.codehaus.stax2.XMLStreamReader2; //导入依赖的package包/类
@Test
public void testParsingMonogram_meeting_shouldWork() throws Exception {
    InputStream inputStream = this.getClass().getResourceAsStream("/hal-00576900.corpus.tei.xml");
    XMLStreamReader2 reader = (XMLStreamReader2) inputFactory.createXMLStreamReader(inputStream);

    StaxUtils.traverse(reader, target);

    final Conference_Event conferenceEvent = target.getConferenceEvent();
    assertThat(conferenceEvent, notNullValue());
    assertThat(conferenceEvent.getMonograph(), notNullValue());
    assertThat(conferenceEvent.getStart_date(), is("2010-07-20"));
    assertThat(conferenceEvent.getEnd_date(), is(""));
    assertThat(conferenceEvent.getConference().getTitle(), is("Accuracy2010"));

    final Address address = conferenceEvent.getAddress();
    assertThat(address.getSettlement(), is("Leicester"));
    assertThat(address, notNullValue());

    final Country country = address.getCountry();
    assertThat(country, notNullValue());
    assertThat(country.getIso(), is("GB"));
}
 
开发者ID:anHALytics,项目名称:anhalytics-core,代码行数:23,代码来源:PublicationTeiDocumentStaxHandlerTest.java

示例5: testParsingMonogram_meeting2_shouldWork

import org.codehaus.stax2.XMLStreamReader2; //导入依赖的package包/类
@Test
public void testParsingMonogram_meeting2_shouldWork() throws Exception {
    InputStream inputStream = this.getClass().getResourceAsStream("/inria-00510267.corpus.tei.xml");
    XMLStreamReader2 reader = (XMLStreamReader2) inputFactory.createXMLStreamReader(inputStream);

    StaxUtils.traverse(reader, target);

    final Conference_Event conferenceEvent = target.getConferenceEvent();
    assertThat(conferenceEvent, notNullValue());
    assertThat(conferenceEvent.getMonograph(), notNullValue());
    assertThat(conferenceEvent.getStart_date(), is("2010-09-20"));
    assertThat(conferenceEvent.getEnd_date(), is("2010-09-23"));
    assertThat(conferenceEvent.getConference().getTitle(), is("CLEF 2010 - Conference on Multilingual and Multimodal Information Access Evaluation"));

    final Address address = conferenceEvent.getAddress();
    assertThat(address.getSettlement(), is("Padua"));
    assertThat(address, notNullValue());

    final Country country = address.getCountry();
    assertThat(country, notNullValue());
    assertThat(country.getIso(), is("IT"));

}
 
开发者ID:anHALytics,项目名称:anhalytics-core,代码行数:24,代码来源:PublicationTeiDocumentStaxHandlerTest.java

示例6: createSR

import org.codehaus.stax2.XMLStreamReader2; //导入依赖的package包/类
@SuppressWarnings("resource")
protected XMLStreamReader2 createSR(SystemId systemId, InputStream in, String enc,
		boolean forER, boolean autoCloseInput)
    throws XMLStreamException
{
    // sanity check:
    if (in == null) {
        throw new IllegalArgumentException("Null InputStream is not a valid argument");
    }
    ReaderConfig cfg = createPrivateConfig();
    if (enc == null || enc.length() == 0) {
        return createSR(cfg, systemId, StreamBootstrapper.getInstance
                        (null, systemId, in), forER, autoCloseInput);
    }

    /* !!! 17-Feb-2006, TSa: We don't yet know if it's xml 1.0 or 1.1;
     *   so have to specify 1.0 (which is less restrictive WRT input
     *   streams). Would be better to let bootstrapper deal with it
     *   though:
     */
    Reader r = DefaultInputResolver.constructOptimizedReader(cfg, in, false, enc);
    return createSR(cfg, systemId, ReaderBootstrapper.getInstance
                    (null, systemId, r, enc), forER, autoCloseInput);
}
 
开发者ID:FasterXML,项目名称:woodstox,代码行数:25,代码来源:WstxInputFactory.java

示例7: getReader

import org.codehaus.stax2.XMLStreamReader2; //导入依赖的package包/类
@Override
protected XMLStreamReader2 getReader(String contents)
    throws XMLStreamException
{
    try {
        XMLInputFactory f = getInputFactory();
        setCoalescing(f, false); // shouldn't really matter
        setNamespaceAware(f, true);
        
        // First, need to parse using JAXP DOM:
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document doc = db.parse(new InputSource(new StringReader(contents)));
        
        return (XMLStreamReader2) f.createXMLStreamReader(new DOMSource(doc));
    } catch (Exception e) {
        throw new XMLStreamException(e);
    }
}
 
开发者ID:FasterXML,项目名称:woodstox,代码行数:21,代码来源:TestDOMArrayReader.java

示例8: getReader

import org.codehaus.stax2.XMLStreamReader2; //导入依赖的package包/类
private XMLStreamReader2 getReader(String contents,
                                  boolean xmlidEnabled,
                                  boolean nsAware, boolean coal)
    throws XMLStreamException
{
    XMLInputFactory2 f = getInputFactory();
    setSupportDTD(f, true);
    setValidating(f, false);
    setCoalescing(f, coal);
    setNamespaceAware(f, nsAware);
    f.setProperty(XMLInputFactory2.XSP_SUPPORT_XMLID,
                  xmlidEnabled
                  ? XMLInputFactory2.XSP_V_XMLID_TYPING
                  : XMLInputFactory2.XSP_V_XMLID_NONE);
    return constructStreamReader(f, contents);
}
 
开发者ID:FasterXML,项目名称:woodstox,代码行数:17,代码来源:TestXmlId.java

示例9: testWsdlValidation

import org.codehaus.stax2.XMLStreamReader2; //导入依赖的package包/类
public void testWsdlValidation() throws Exception {
	String runMe = System.getProperty("testWsdlValidation");
	if (runMe == null || "".equals(runMe)) {
		return;
	}
	XMLInputFactory2 factory = getInputFactory();
	XMLStreamReader2 reader = (XMLStreamReader2) factory.createXMLStreamReader(getClass().getResourceAsStream("test-message.xml"), "utf-8");
	QName msgQName = new QName("http://server.hw.demo/", "sayHi");
	while (true) {
		int what = reader.nextTag();
		if (what == XMLStreamConstants.START_ELEMENT) {
			if (reader.getName().equals(msgQName)) {
				reader.validateAgainst(schema);
			}
		} else if (what == XMLStreamConstants.END_ELEMENT) {
			if (reader.getName().equals(msgQName)) {
				reader.stopValidatingAgainst(schema);
			}
		} else if (what == XMLStreamConstants.END_DOCUMENT) {
			break;
		}
	}
}
 
开发者ID:FasterXML,项目名称:woodstox,代码行数:24,代码来源:TestWsdlValidation.java

示例10: onEndElement

import org.codehaus.stax2.XMLStreamReader2; //导入依赖的package包/类
/**
 * When the document is closed, add an empty line as document separator.
 */
@Override
public void onEndElement(XMLStreamReader2 reader) {
    if (reader.getName().getLocalPart().equals("document")) {
        try {
            writer.write(sb.append("\n").toString());
        } catch (IOException e) {
            throw new RuntimeException();
        }
        sb = new StringBuilder();
    } else if (reader.getName().getLocalPart().equals("sentence")) {
        inSentence = false;
    } else if (reader.getName().getLocalPart().equals("ENAMEX")) {
        inNamedEntity = false;
        entityType = null;
        entitySubType = null;
    }
}
 
开发者ID:kermitt2,项目名称:grobid-ner,代码行数:21,代码来源:INRIALeMondeCorpusStaxHandler.java

示例11: main

import org.codehaus.stax2.XMLStreamReader2; //导入依赖的package包/类
/**
 * How to use it
 * <p>
 * This class require a single parameter which is the input file containng the french
 * corpus from Le Monde manually annotated.
 * <p>
 * The class will output the cONLL 2013 format in a file having the same name as the input
 * suffixed with .output.
 */
public static void main(String[] args) throws IOException, XMLStreamException {

    if (args.length == 0) {
        System.out.println("Missing input file. First parameter.");
        System.exit(-1);
    }

    WstxInputFactory inputFactory = new WstxInputFactory();

    Writer writer = new FileWriter(args[0] + ".output");
    INRIALeMondeCorpusStaxHandler inriaLeMondeCorpusStaxHandler = new INRIALeMondeCorpusStaxHandler(writer);

    InputStream is = new FileInputStream(args[0]);
    XMLStreamReader2 reader = (XMLStreamReader2) inputFactory.createXMLStreamReader(is);

    StaxUtils.traverse(reader, inriaLeMondeCorpusStaxHandler);

    writer.close();
}
 
开发者ID:kermitt2,项目名称:grobid-ner,代码行数:29,代码来源:INRIALeMondeCorpusStaxHandler.java

示例12: parseGsafeedElement

import org.codehaus.stax2.XMLStreamReader2; //导入依赖的package包/类
private Feed parseGsafeedElement(String datasource, String feedtype, XMLStreamReader2 xmlReader) throws XMLStreamException, ParseFeedException  {
	List<FeedGroup> groups = new ArrayList<FeedGroup>();
	while (xmlReader.hasNext()) {
		xmlReader.next();
		if (xmlReader.getEventType() == XMLStreamConstants.START_ELEMENT) {
			if (XML_GSAFEED.equals(xmlReader.getLocalName())) {
				//Ignored
			}
			if (XML_HEADER.equals(xmlReader.getLocalName())) {
				//datasource
				//feedtype
			}
			if (XML_GROUP.equals(xmlReader.getLocalName())) {
				FeedGroup group = this.parseGroupElement(datasource, feedtype, xmlReader);
				groups.add(group);
			}
		}
	}
	return new FeedImpl(datasource, feedtype, groups);
}
 
开发者ID:BassJel,项目名称:Jouve-Project,代码行数:21,代码来源:FeedStaxParser.java

示例13: parseGroupElement

import org.codehaus.stax2.XMLStreamReader2; //导入依赖的package包/类
private FeedGroup parseGroupElement(String datasource, String feedtype, XMLStreamReader2 xmlReader) throws ParseFeedException, XMLStreamException {
	List<FeedRecord> records = new ArrayList<FeedRecord>();
	String action = xmlReader.getAttributeValue("", XML_GROUP_ACTION);
	while (xmlReader.hasNext()) {
		xmlReader.next();
		if (xmlReader.getEventType() == XMLStreamConstants.START_ELEMENT) {
			if (XML_RECORD.equals(xmlReader.getLocalName())) {
				FeedRecord record = this.parseRecordElement(datasource, feedtype, action, xmlReader);
				records.add(record);
			}
		}
		if (xmlReader.getEventType() == XMLStreamConstants.END_ELEMENT) {
			if (XML_GROUP.equals(xmlReader.getLocalName())) {
				break;
			}
		}		
	}	
	
	FeedGroup group = new FeedGroupImpl(action, records);
	return group;
}
 
开发者ID:BassJel,项目名称:Jouve-Project,代码行数:22,代码来源:FeedStaxParser.java

示例14: parseMetadataElement

import org.codehaus.stax2.XMLStreamReader2; //导入依赖的package包/类
private FeedMetadata parseMetadataElement(XMLStreamReader2 xmlReader) throws ParseFeedException, XMLStreamException {
	//in metadata element
	List<FeedMeta> metas = new ArrayList<FeedMeta>();
	while (xmlReader.hasNext()) {
		xmlReader.next();
		if (xmlReader.getEventType() == XMLStreamConstants.START_ELEMENT) {
			if (XML_META.equals(xmlReader.getLocalName())) {
				FeedMeta meta = this.parseMetaElement(xmlReader);
				metas.add(meta);
			}
		}
		if (xmlReader.getEventType() == XMLStreamConstants.END_ELEMENT) {
			if (XML_METADATA.equals(xmlReader.getLocalName())) {
				break;
			}
		}
	}
	FeedMetadata metadata = new FeedMetadataImpl(metas);
	return metadata;
}
 
开发者ID:BassJel,项目名称:Jouve-Project,代码行数:21,代码来源:FeedStaxParser.java

示例15: parseForwardingRule

import org.codehaus.stax2.XMLStreamReader2; //导入依赖的package包/类
protected void parseForwardingRule(NetPlan netPlan, long layerId, XMLStreamReader2 xmlStreamReader , DoubleMatrix2D f_de) throws XMLStreamException
{
	long linkId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "linkId"));
	long demandId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "demandId"));
	double splittingRatio = xmlStreamReader.getAttributeAsDouble(xmlStreamReader.getAttributeIndex(null, "splittingRatio"));

	f_de.set (mapOldId2Demand.get(Pair.of (layerId,demandId)).index , mapOldId2Link.get(Pair.of(layerId , linkId)).index  , splittingRatio);

	while(xmlStreamReader.hasNext())
	{
		xmlStreamReader.next();

		switch(xmlStreamReader.getEventType())
		{
			case XMLEvent.START_ELEMENT:
				String startElementName = xmlStreamReader.getName().toString();
				switch(startElementName)
				{
					case "attribute":
						break;

					default:
						throw new RuntimeException("Bad");
				}

				break;

			case XMLEvent.END_ELEMENT:
				String endElementName = xmlStreamReader.getName().toString();
				if (endElementName.equals("forwardingRule")) return;
				break;
		}
	}

	throw new RuntimeException("'Forwarding rule' element not parsed correctly (end tag not found)");
}
 
开发者ID:girtel,项目名称:Net2Plan,代码行数:37,代码来源:ReaderNetPlanN2PVersion_3.java


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