本文整理汇总了Java中org.codehaus.jettison.mapped.MappedXMLStreamReader类的典型用法代码示例。如果您正苦于以下问题:Java MappedXMLStreamReader类的具体用法?Java MappedXMLStreamReader怎么用?Java MappedXMLStreamReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MappedXMLStreamReader类属于org.codehaus.jettison.mapped包,在下文中一共展示了MappedXMLStreamReader类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseFile
import org.codehaus.jettison.mapped.MappedXMLStreamReader; //导入依赖的package包/类
@Override
public Games parseFile ( Reader reader ) {
Games games = null;
try {
JAXBContext jc = JAXBContext.newInstance ( Games.class );
JSONObject obj = new JSONObject ( readJSONFile ( reader ) );
Configuration config = new Configuration ();
MappedNamespaceConvention con = new MappedNamespaceConvention ( config );
XMLStreamReader xmlStreamReader = new MappedXMLStreamReader ( obj , con );
Unmarshaller unmarshaller = jc.createUnmarshaller ();
games = (Games) unmarshaller.unmarshal ( xmlStreamReader );
} catch ( Exception e ) {
log ( "" , e );
}
return games;
}
示例2: parse
import org.codehaus.jettison.mapped.MappedXMLStreamReader; //导入依赖的package包/类
private OMElement parse(StringBuilder sb) throws JSONException, XMLStreamException, IOException {
StringWriter sw = new StringWriter(FiveKB);
JSONObject jsonObject = new JSONObject(sb.toString());
AbstractXMLStreamReader reader = new MappedXMLStreamReader(jsonObject);
XMLStreamWriter xmlStreamWriter = factory.createXMLStreamWriter(sw);
xmlStreamWriter.writeStartDocument();
while (reader.hasNext()) {
int x = reader.next();
switch (x) {
case XMLStreamConstants.START_ELEMENT:
xmlStreamWriter.writeStartElement(reader.getPrefix(), reader.getLocalName(),
reader.getNamespaceURI());
int namespaceCount = reader.getNamespaceCount();
for (int i = namespaceCount - 1; i >= 0; i--) {
xmlStreamWriter.writeNamespace(reader.getNamespacePrefix(i),
reader.getNamespaceURI(i));
}
int attributeCount = reader.getAttributeCount();
for (int i = 0; i < attributeCount; i++) {
xmlStreamWriter.writeAttribute(reader.getAttributePrefix(i),
reader.getAttributeNamespace(i),
reader.getAttributeLocalName(i),
reader.getAttributeValue(i));
}
break;
case XMLStreamConstants.START_DOCUMENT:
break;
case XMLStreamConstants.CHARACTERS:
xmlStreamWriter.writeCharacters(reader.getText());
break;
case XMLStreamConstants.CDATA:
xmlStreamWriter.writeCData(reader.getText());
break;
case XMLStreamConstants.END_ELEMENT:
xmlStreamWriter.writeEndElement();
break;
case XMLStreamConstants.END_DOCUMENT:
xmlStreamWriter.writeEndDocument();
break;
case XMLStreamConstants.SPACE:
break;
case XMLStreamConstants.COMMENT:
xmlStreamWriter.writeComment(reader.getText());
break;
case XMLStreamConstants.DTD:
xmlStreamWriter.writeDTD(reader.getText());
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION:
xmlStreamWriter
.writeProcessingInstruction(reader.getPITarget(), reader.getPIData());
break;
case XMLStreamConstants.ENTITY_REFERENCE:
xmlStreamWriter.writeEntityRef(reader.getLocalName());
break;
default:
throw new RuntimeException("Error in converting JSON to XML");
}
}
xmlStreamWriter.writeEndDocument();
xmlStreamWriter.flush();
xmlStreamWriter.close();
OMElement element = AXIOMUtil.stringToOM(sw.toString());
OMNamespace ns = OMAbstractFactory.getOMFactory().createOMNamespace(
JsonRoot.getNamespaceURI(), JsonRoot.getPrefix());
element.setNamespace(ns);
return element;
}