Skip to content

Latest commit

 

History

History
82 lines (49 loc) · 2.88 KB

README.md

File metadata and controls

82 lines (49 loc) · 2.88 KB

KtXml

Maven Central

Minimal platform-agnostic non-validating XML pull parser based on kxml2.

The most significant changes (relative to XmlPull / KXml2) are:

  • Replaced the Reader as input with CharIterator support, as Java streams are not available for Kotlin native.
  • Reduced the number of places where null is returned
  • Factories removed

Import in build.gradle.kts for a "shared" KMP module:

(...)

kotlin {
  
      (...)
  
      sourceSets {
          val commonMain by getting {
              dependencies {
                  implementation("org.kobjects.ktxml:core:0.3.2")
                  (...)
              }
          }
          
      (...)  
              

KtXML is implemented in pure Kotlin, so it should work on all platforms supported by Kotlin.

Usage

The most important calls in KtXml are next() and nextToken().

  • next() moves to the next "high level" token and returns the token type. It skips over comments and processing instructions and automatically decodes entity references. It also might aggregate text content.

  • nextToken() moves to the next "low level" token including whitespace, processing instructions, comments and entity references.

After a call to next() or nextToken(), the details of the current token (such as tag attributes) can be queried from the parser; see XmlPullParser

Typically these calls are used to implement recursive descend parsing of a specific XML format.

Please always use the interface (XmlPullParser) and never the concrete parser implementation (MiniXmlPullParser) when passing the parser around.

For a set of small code examples, please take a look at the test.

For more information about the API, please refer to the KtXml API documentation.

Use cases

FAQ

How can I stream data to the parser?

See #6

Where is Wbxml / kDom support from kXML2?

If you are missing anything from kXML2, please file a feature request by creating a corresponding issue in the github issue tracker.

I have a different problem!

Please file an issue using the github issue tracker.

Background / Design

Brainstorming document: https://docs.google.com/document/d/1OXG5F5I-Gp-65cN8THWB1LMTZDnRS96CIBenPcusDDA/edit?usp=sharing