GithubHelp home page GithubHelp logo

dataliquid / commons-xml Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 78 KB

Simplifying XML Processing and Manipulation with Java

License: Apache License 2.0

Java 100.00%
xml-parsing xml-validation xpath xml-creation dom-utils xml-utils

commons-xml's Introduction

commons-xml

Welcome to the commons-xml project! This repository contains a Java library that provides various utility classes and functions for working with XML documents. The library is designed to make common tasks related to XML processing and manipulation easier.

Features

  • XML Parsing: The library provides an easy way to parse XML documents and convert them into a structured data format.
  • XML Creation: You can programmatically create XML documents while maintaining the desired structure and hierarchy.
  • XPath Support: The library allows you to use XPath expressions to selectively access specific elements or attributes in an XML document.
  • Validation: You can validate XML documents against an XML schema and ensure they adhere to the specified rules.

Usage

To use the commons-xml library in your project, you can add it as a Maven dependency. Add the following section to your pom.xml file:

<dependencies>
    <dependency>
        <groupId>com.dataliquid.commons</groupId>
        <artifactId>commons-xml</artifactId>
        <version>1.0.2</version>
    </dependency>
</dependencies>

Example

The given example utilizes the DomUtils class from the commons-xml library to create and manipulate an XML document. It performs the following steps:

  • Creates an empty XML document using DomUtils.createDocument().
  • Creates a root element named "root" and adds it to the document.
  • Creates a child element named "child" and sets its text content to "Hello, World!". The child element is appended to the root element.
  • Converts the document to an XML string representation using DomUtils.asXml(document).
  • Prints the generated XML string to the console.

In summary, this example demonstrates how to create an XML document, add elements to it, and obtain the XML representation of the document using the DomUtils class.

import com.dataliquid.commons.xml.DomUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class Example {
    public static void main(String[] args) {
        // Create an empty XML document using DomUtils
        Document document = DomUtils.createDocument();

        // Create the root element
        Element rootElement = DomUtils.createElement(document, "root");
        DomUtils.appendChild(document, rootElement);

        // Add a child element
        Element childElement = DomUtils.createElement(document, "child");
        DomUtils.setTextContent(childElement, "Hello, World!");
        DomUtils.appendChild(rootElement, childElement);

        // Represent the document as xml string using DomUtils
        String xml = DomUtils.asXml(document);
        System.out.println("XML: " + xml);
    }
}

This example demonstrates the usage of the DomUtils class to create an XML document, add a root element and a child element to it. Then, it retrieves the xml as string and print it out.

Please note that you need to add the commons-xml library to your project in order to use the DomUtils class.

Follow this link, you will be taken to the EXAMPLES.md file where you can find more examples. These examples are intended to help you understand and utilize the functionality of the Commons-XML project.

Contribution

We welcome contributions to the commons-xml project! If you have found a bug, want to propose an improvement, or add a new feature, please follow these steps:

  • Fork the repository.
  • Create a new branch for your changes: git checkout -b my-feature.
  • Make your changes and run tests.
  • Commit your changes: git commit -m 'Add my feature'.

commons-xml's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.