Class XlsxParser


  • public class XlsxParser
    extends java.lang.Object
    A StAX parser to convert Xlsx to JSON format.

    The syntax as follows

    1. All are attributes:

      For example,

      <foo a="a"/>
       
      Result:
      
       {
           "foo": {
               "a": "a"
           }
       }
       
    2. Attributes and child element:

      For example,

      <foo a="a">
           <bar>baz</bar>
       </foo>
       
      Result:
      
       {
           "foo": {
                     "": ["a"], // store for the attr key info
                     "a": "a",  // attribute
                     "bar": {
                    "_": "baz" // text only
                     }
           }
       }
      
    3. Attributes and text node only:

      For example,

      <foo a="a">bar</foo>
       
      Result:
      
       {
           "foo": {
               "a": "a", // attribute
               "_": "baz" // text only
           }
       }
      
    4. Text node only:

      For example,

      <foo>bar</foo>
       
      Result:
      
       {
           "foo": {
               "_": "baz" // text only
           }
       }
      
    5. Child element and text node only:

      For example,

      <foo><bar>baz</bar></foo>
       
      Result:
      
       {
           "foo": {
                     "bar": {
                   "_": "baz" // text only
                     }
           }
       }
      
    6. Multiple child elements with the same key:

      For example,

      <foo><bar a="a"></bar><bar b="b"></bar><baz/></foo>
       
      Result:
      
       {
           "foo": {
               "bar": [{
                          "a": "a"
                      }, {
                    "b": "b"
                      }],
               "baz": null // self-closed tag
            }
       }
      
    Author:
    jumperchen
    • Constructor Summary

      Constructors 
      Constructor Description
      XlsxParser()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static JSONObject parse​(java.lang.String name, java.util.zip.ZipInputStream zipFile)  
      static void parseElement​(javax.xml.stream.XMLStreamReader reader, JSONAware json, java.util.Map<java.lang.String,​java.util.function.Supplier<JSONNode>> schemaNodes)  
      static JSONObject parseXML​(javax.xml.stream.XMLStreamReader reader)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • XlsxParser

        public XlsxParser()
    • Method Detail

      • parse

        public static JSONObject parse​(java.lang.String name,
                                       java.util.zip.ZipInputStream zipFile)
                                throws java.io.IOException,
                                       javax.xml.stream.XMLStreamException
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • parseXML

        public static JSONObject parseXML​(javax.xml.stream.XMLStreamReader reader)
                                   throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • parseElement

        public static void parseElement​(javax.xml.stream.XMLStreamReader reader,
                                        JSONAware json,
                                        java.util.Map<java.lang.String,​java.util.function.Supplier<JSONNode>> schemaNodes)
                                 throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException