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


Java JsonXMLConfig类代码示例

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


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

示例1: xmlToJson

import de.odysseus.staxon.json.JsonXMLConfig; //导入依赖的package包/类
void xmlToJson(InputStream xmlInput, OutputStream jsonOutput) throws XMLStreamException
{
   JsonXMLConfig config = new JsonXMLConfigBuilder()
         .autoArray(true)
         .autoPrimitive(false)
         .fieldPrefix("")
         .contentField("content")
         .build();
   
   XMLEventReader reader = XMLInputFactory.newInstance().createXMLEventReader(xmlInput);
   XMLEventWriter writer = new JsonXMLOutputFactory(config).createXMLEventWriter(jsonOutput);
   
   writer.add(reader);
   
   reader.close();
   writer.close();
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:18,代码来源:SearchController.java

示例2: getDestination

import de.odysseus.staxon.json.JsonXMLConfig; //导入依赖的package包/类
@Override
public Destination getDestination(WebApp webApp, HttpServletRequest req, 
    HttpServletResponse resp, OutputStream os, Properties outputProperties) throws XMLStreamException {
  JsonXMLConfig config = new JsonXMLConfigBuilder()
      .autoArray(autoArray)
      .autoPrimitive(autoPrimitive)
      .multiplePI(multiplePI)
      .namespaceDeclarations(namespaceDeclarations)
      .namespaceSeparator(namespaceSeparator)
      .prettyPrint(prettyPrint)
      .virtualRoot(virtualRoot)
      .repairingNamespaces(repairingNamespaces)
      .namespaceMappings(namespaceMappings)
      .build();
  XMLOutputFactory factory = new JsonXMLOutputFactory(config);
  return new XMLStreamWriterDestination(factory.createXMLStreamWriter(os, outputProperties.getProperty("encoding", "UTF-8")));            
}
 
开发者ID:Armatiek,项目名称:xslweb,代码行数:18,代码来源:JSONSerializerStep.java

示例3: call

import de.odysseus.staxon.json.JsonXMLConfig; //导入依赖的package包/类
@Override
public StringValue call(XPathContext context, Sequence[] arguments) throws XPathException {                            
  StringWriter sw = new StringWriter();      
  JsonXMLConfig config = new JsonXMLConfigBuilder().        
      prettyPrint(true).
      build();    
  XMLOutputFactory jFactory = new JsonXMLOutputFactory(config);                  
  TransformerFactory tFactory = new TransformerFactoryImpl();      
  try {
    SequenceIterator iter = arguments[0].iterate(); 
    Item item;
    while ((item = iter.next()) != null) {
      if (item instanceof NodeInfo) {
        Transformer transformer = tFactory.newTransformer();            
        XMLStreamWriter xsw = jFactory.createXMLStreamWriter(sw);            
        transformer.transform((NodeInfo) item, new StAXResult(xsw));                                   
      } else {
        sw.append(item.getStringValue());
      }
    }
  } catch (Exception e) {
    throw new XPathException("Error serializing sequence to JSON", e);
  }
  return StringValue.makeStringValue(sw.toString());              
}
 
开发者ID:Armatiek,项目名称:xslweb,代码行数:26,代码来源:SerializeJSON.java

示例4: convertXmlToJson

import de.odysseus.staxon.json.JsonXMLConfig; //导入依赖的package包/类
/**
 * Converts xml to json.
 *
 * @param xml xml as byte array.
 * @return json as byte array.
 */
public byte[] convertXmlToJson(byte[] xml) {
    JsonXMLConfig config = new JsonXMLConfigBuilder()
            .prettyPrint(true)
            .autoArray(true)
            .autoPrimitive(true)
            .build();
    XMLInputFactory reader = XMLInputFactory.newInstance();
    JsonXMLOutputFactory writer = new JsonXMLOutputFactory(config);
    return convert(reader, writer, xml);
}
 
开发者ID:eea,项目名称:eionet.webq,代码行数:17,代码来源:JsonXMLBidirectionalConverter.java

示例5: convertJsonToXml

import de.odysseus.staxon.json.JsonXMLConfig; //导入依赖的package包/类
/**
 * Converts json to xml.
 *
 * @param json json as byte array.
 * @return xml as byte array.
 */
public byte[] convertJsonToXml(byte[] json) {
    JsonXMLConfig config = new JsonXMLConfigBuilder()
        .prettyPrint(true)
        .multiplePI(false)
        .build();
    XMLInputFactory reader = new JsonXMLInputFactory(config);
    XMLOutputFactory writer = XMLOutputFactory.newInstance();
    return convert(reader, writer, json);
}
 
开发者ID:eea,项目名称:eionet.webq,代码行数:16,代码来源:JsonXMLBidirectionalConverter.java

示例6: xmlQuizzToJson

import de.odysseus.staxon.json.JsonXMLConfig; //导入依赖的package包/类
/**
 * . Lit le fichier de quizz XML xmlInput, ecrit le test convertit en JSON
 * dans le fichier jsonOutput
 *
 * @param xmlInput
 *            Ficher de Quizz XML
 * @param jsonOutput
 *            Fichier de sortie JSON
 * @throws IOException
 *             exception entrée/sortie
 * @throws FactoryConfigurationError
 *             Erreur de configurations
 * @throws XMLStreamException
 *             exception de flux XML
 */
public static void xmlQuizzToJson(final File xmlInput, final File jsonOutput)
        throws IOException, XMLStreamException, FactoryConfigurationError {

    InputStream is = new FileInputStream(xmlInput);
    OutputStream os = new FileOutputStream(jsonOutput);

    Reader r = new InputStreamReader(is, "UTF-8");
    Writer w = new OutputStreamWriter(os, "UTF-8");

    JsonXMLConfig config = new JsonXMLConfigBuilder().autoArray(true)
            .autoPrimitive(true).prettyPrint(true).build();
    try {
        /*
         * Create reader (XML).
         */
        XMLEventReader reader = XMLInputFactory.newInstance()
                .createXMLEventReader(r);

        /*
         * Create writer (JSON).
         */
        XMLEventWriter writer = new JsonXMLOutputFactory(config)
                .createXMLEventWriter(w);

        /*
         * Copy events from reader to writer.
         */
        writer.add(reader);

        /*
         * Close reader/writer.
         */
        reader.close();
        writer.close();
    } finally {
        /*
         * As per StAX specification, XMLEventReader/Writer.close() doesn't
         * close the underlying stream.
         */
        r.close();
        w.close();
        os.close();
        is.close();
    }
}
 
开发者ID:loclamor,项目名称:morphoQuizz,代码行数:61,代码来源:QuizzConverter.java


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