https://github.com/irgaly/original-characters-stax-xml-parser
A Stax Parser Wrapper with original texts from input XML.
https://github.com/irgaly/original-characters-stax-xml-parser
java kotlin stax xml
Last synced: 3 months ago
JSON representation
A Stax Parser Wrapper with original texts from input XML.
- Host: GitHub
- URL: https://github.com/irgaly/original-characters-stax-xml-parser
- Owner: irgaly
- License: other
- Created: 2022-01-26T12:36:44.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-07-13T05:56:16.000Z (12 months ago)
- Last Synced: 2025-07-13T07:35:46.532Z (12 months ago)
- Topics: java, kotlin, stax, xml
- Language: Kotlin
- Homepage:
- Size: 406 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# original-characters-stax-xml-parser
A Stax Parser Wrapper with original texts from input XML.
This library is useful to parse and modify XML, with preserving original characters and original XML
structures.
exmple: preserving spaces and indent tabs, don't extract `{unicode};`, don't replace `>`
with `>`, don't replace XML empty tag...
This is a simple wrapper to [Woodstox](https://github.com/FasterXML/woodstox) Stax2 XML Parser.
## Usage
This library is published to Maven Central Repository.
Ensure `mavenCentral()` is declared.
`settings.gradle.kts`
```kotlin
dependencyResolutionManagement {
repositories {
//...
mavenCentral()
}
}
```
Add dependencies.
`build.gradle.kts`
```kotlin
dependencies {
implementation("io.github.irgaly.xml:original-characters-stax:1.1.0")
}
```
Then use library!
## Class Documents
[There are KDoc references.](docs/index.md)
## OriginalCharactersStaxXmlParser class
OriginalCharactersStaxXml class sample.
This class is a simple wrapper class to Woodstox's WstxEventReader class.
```kotlin
val inputStream = File("input.xml").inputStream()
val parser = OriginalCharactersStaxXmlParser(inputStream)
while (parser.hasNext()) {
val event = parser.nextEvent()
println("original text:[${event.originalText}]")
}
parser.close() // parser closes inputStream too.
```
parser.nextEvent() returns XmlEvent, that has both of Stax original Event and XML original Text.
```kotlin
event.event // Stax2's XMLEvent2
event.originalText // Original XML's Texts
```
That sample code's input and output is below.
`input.xml`
```xml
' &
ðŸš
```
outputs
```shell
original text:[]
original text:[
]
original text:[]
original text:[
]
original text:[]
original text:[
]
original text:[]
original text:[
]
original text:[]
original text:[' &]
original text:[]
original text:[
]
original text:[]
original text:[ðŸš]
original text:[]
original text:[
]
original text:[]
original text:[]
original text:[
]
original text:[]
original text:[
]
original text:[]
original text:[]
```
## More documentation for Stax2
* [Github Woodstox](https://github.com/FasterXML/woodstox)
* Stax Configurations
* [Stax1 Properties](https://cowtowncoder.medium.com/configuring-woodstox-xml-parser-basic-stax-properties-39bdf88c18ec)
* [Stax2 Properties](https://cowtowncoder.medium.com/configuring-woodstox-xml-parser-stax2-properties-c80ef5a32ef1)
* [Woodstox Properties](https://cowtowncoder.medium.com/configuring-woodstox-xml-parser-woodstox-specific-properties-1ce5030a5173)