Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

com.github.codemonstur:simplexml

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.github.codemonstur:simplexml

A clean and simple XML parser, serializer, and deserializer.

  • 3.2.0
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

GitHub Release Maven Central MIT Licence

SimpleXml

After a number of bad experiences with XML parsing in Java I decided to write my own parser.

This project has the following characteristics; correct XML parsing, small, few dependencies, thread-safe, user friendly API, secure.

Version 3.x depends on Java 19. For Java 8 support you have to use 2.x versions.

How to use

The unit tests in src/test/java/unittests can give you a good idea of the capabilities of SimpleXml. There are also a number of small example programs in src/test/java/example that showcase various features.

Examples

Implemented annotations

How to get

It's in maven central.

<dependency>
    <groupId>com.github.codemonstur</groupId>
    <artifactId>simplexml</artifactId>
    <version>3.2.0</version>
</dependency>

Serializing

The simplest case possible:

import xmlparser.XmlParser;

public class MyObject {
    String name;
}

MyObject object = new MyObject();
object.name = "test";

final XmlParser parser = new XmlParser();
System.out.println(parser.toXml(object));

This code will output:

<myobject>
  <name>test</name>
</myobject>

There are more serialization options

  • Renaming fields
  • Fields as attributes
  • Field as text node
  • Skipping fields
  • etc...

For more documentation on serializing look in src/docs/serialize.md.

Deserializing

The simplest case possible:

import xmlparser.XmlParser;

public class MyObject {
    String name;
}

final XmlParser parser = new XmlParser();
final MyObject object = parser.fromXml("<myobject><name>test</name></myobject>", MyObject.class);
System.out.println(object.name);

This code will output:

test

The deserializer will respect the same annotations as the serializer

  • Renamed fields
  • Attributes
  • Text nodes
  • Skipped fields
  • etc...

If there is a feature you would like to have, but doesn't exist, please let me know.

License

The MIT license. And I left out the copyright notice everywhere because I just don't care.

FAQs

Package last updated on 22 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc