CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-eclipse-jetty--jetty-xml

XML-based configuration utilities for Eclipse Jetty providing IoC mechanism for component configuration.

Pending
Overview
Eval results
Files

xml-parser.mddocs/

XML Parser and Document Processing

Advanced XML parsing capabilities with validation, entity resolution, and DOM-like tree processing. The XmlParser class wraps standard JAXP parsers with convenient error handling and provides a mini DOM-like document tree for configuration processing.

Capabilities

XmlParser Class

XML parser wrapper that provides validation, entity resolution, and document tree processing.

/**
 * XML Parser wrapper with convenient error and entity handlers
 */
class XmlParser {
    /**
     * Construct XmlParser with default validation settings
     */
    XmlParser();
    
    /**
     * Construct XmlParser with specified validation setting
     * @param validating true to enable validation, false to disable
     */
    XmlParser(boolean validating);
}

Parser Configuration

Configure parser behavior and validation settings.

/**
 * Set validation mode
 * @param validating true to enable validation
 */
void setValidating(boolean validating);

/**
 * Get current validation mode
 * @return true if validation is enabled
 */
boolean isValidating();

/**
 * Get underlying SAX parser
 * @return SAX parser instance
 */
SAXParser getSAXParser();

XML Catalog Support

Add XML catalogs for entity resolution.

/**
 * Add XML catalog for entity resolution
 * @param catalogXml URI to catalog XML file
 */
void addCatalog(URI catalogXml);

/**
 * Add catalog with base class location
 * @param catalogXml URI to catalog XML file
 * @param baseClassLocation base class for relative resolution
 */
void addCatalog(URI catalogXml, Class<?> baseClassLocation);

XPath Support

Set simple XPath expressions for selective parsing.

/**
 * Set simple XPath for partial tree selection
 * @param xpath XPath expression
 */
void setXpath(String xpath);

/**
 * Get current XPath expression
 * @return XPath string or null
 */
String getXpath();

Content Handling

Add custom content handlers for specific XML elements.

/**
 * Add content handler for specific tag
 * @param trigger tag name to trigger handler
 * @param observer content handler to invoke
 */
void addContentHandler(String trigger, ContentHandler observer);

Document Parsing

Parse XML documents from various sources.

/**
 * Parse XML from input source
 * @param source SAX input source
 * @return root node of parsed document
 * @throws IOException if I/O error occurs
 * @throws SAXException if XML parsing error occurs
 */
Node parse(InputSource source) throws IOException, SAXException;

/**
 * Parse XML from URL string
 * @param url URL string to XML document
 * @return root node of parsed document
 * @throws IOException if I/O error occurs
 * @throws SAXException if XML parsing error occurs
 */
Node parse(String url) throws IOException, SAXException;

/**
 * Parse XML from file
 * @param file file containing XML document
 * @return root node of parsed document
 * @throws IOException if I/O error occurs
 * @throws SAXException if XML parsing error occurs
 */
Node parse(File file) throws IOException, SAXException;

/**
 * Parse XML from input stream
 * @param in input stream containing XML document
 * @return root node of parsed document
 * @throws IOException if I/O error occurs
 * @throws SAXException if XML parsing error occurs
 */
Node parse(InputStream in) throws IOException, SAXException;

Document Metadata

Get metadata about parsed documents.

/**
 * Get DTD identifier from parsed document
 * @return DTD identifier string or null
 */
String getDTD();

Document Tree API

XmlParser.Node

Represents XML elements with attributes and content, providing DOM-like access to the document tree.

/**
 * XML element node with attributes and content
 */
static class Node {
    /**
     * Get parent node
     * @return parent node or null for root
     */
    Node getParent();
    
    /**
     * Get element tag name
     * @return tag name
     */
    String getTag();
    
    /**
     * Get XPath-like path to this node
     * @return path string
     */
    String getPath();
}

Attribute Access

Access and query element attributes.

/**
 * Get all attributes
 * @return array of attributes
 */
Attribute[] getAttributes();

/**
 * Get attribute value by name
 * @param name attribute name
 * @return attribute value or null if not found
 */
String getAttribute(String name);

/**
 * Get attribute value with default
 * @param name attribute name
 * @param dft default value if attribute not found
 * @return attribute value or default
 */
String getAttribute(String name, String dft);

Child Node Access

Navigate and access child nodes.

/**
 * Get first child node with specified tag
 * @param tag tag name to find
 * @return first matching child node or null
 */
Node get(String tag);

/**
 * Get child node as string content
 * @param tag child tag name
 * @param tags include tag names in output
 * @param trim trim whitespace
 * @return string content
 */
String getString(String tag, boolean tags, boolean trim);

/**
 * Iterate over child nodes with specified tag
 * @param tag tag name to iterate
 * @return iterator over matching child nodes
 */
Iterator<Node> iterator(String tag);

List Operations

Node implements List interface for child access.

/**
 * Get number of child nodes
 * @return child count
 */
int size();

/**
 * Get child by index
 * @param i child index
 * @return child object (Node or String)
 */
Object get(int i);

/**
 * Add child at index
 * @param i index position
 * @param obj child object to add
 */
void add(int i, Object obj);

/**
 * Remove all children
 */
void clear();

String Conversion

Convert nodes to string representation.

/**
 * Convert to string representation
 * @param tag include tag names in output
 * @return string representation
 */
String toString(boolean tag);

XmlParser.Attribute

Represents XML attributes with name and value.

/**
 * XML attribute with name and value
 */
static class Attribute {
    /**
     * Get attribute name
     * @return attribute name
     */
    String getName();
    
    /**
     * Get attribute value
     * @return attribute value
     */
    String getValue();
}

Usage Examples

Basic Parsing

import org.eclipse.jetty.xml.XmlParser;
import java.io.File;

// Create parser with validation
XmlParser parser = new XmlParser(true);

// Parse XML file
XmlParser.Node root = parser.parse(new File("config.xml"));

// Access root element
String rootTag = root.getTag();
String classAttr = root.getAttribute("class");

Navigating Document Tree

// Get child nodes
XmlParser.Node childNode = root.get("Set");
String nameAttr = childNode.getAttribute("name");

// Iterate over all children with specific tag
Iterator<XmlParser.Node> setNodes = root.iterator("Set");
while (setNodes.hasNext()) {
    XmlParser.Node setNode = setNodes.next();
    String name = setNode.getAttribute("name");
    // Process set node...
}

Using XML Catalogs

import java.net.URI;

// Add catalog for entity resolution
XmlParser parser = new XmlParser();
parser.addCatalog(URI.create("file:///path/to/catalog.xml"));

// Parse with entity resolution
XmlParser.Node root = parser.parse("config-with-entities.xml");

Validation and Error Handling

try {
    XmlParser parser = new XmlParser(true); // Enable validation
    XmlParser.Node root = parser.parse("config.xml");
    
    // Get DTD information
    String dtd = parser.getDTD();
    
} catch (SAXException e) {
    // Handle XML parsing errors
    System.err.println("XML parsing error: " + e.getMessage());
} catch (IOException e) {
    // Handle I/O errors
    System.err.println("I/O error: " + e.getMessage());
}

XPath Filtering

// Parse only specific parts of document
XmlParser parser = new XmlParser();
parser.setXpath("/Configure/Set[@name='port']");

XmlParser.Node root = parser.parse("large-config.xml");
// Only port setting nodes will be in the tree

Custom Content Handlers

import org.xml.sax.ContentHandler;
import org.xml.sax.helpers.DefaultHandler;

// Add custom handler for specific elements
ContentHandler customHandler = new DefaultHandler() {
    @Override
    public void startElement(String uri, String localName, 
                           String qName, Attributes attributes) {
        System.out.println("Processing custom element: " + qName);
    }
};

XmlParser parser = new XmlParser();
parser.addContentHandler("CustomElement", customHandler);

XmlParser.Node root = parser.parse("config-with-custom.xml");

Accessing Attributes and Content

XmlParser.Node configNode = root;

// Get all attributes
XmlParser.Attribute[] attributes = configNode.getAttributes();
for (XmlParser.Attribute attr : attributes) {
    String name = attr.getName();
    String value = attr.getValue();
    System.out.println(name + "=" + value);
}

// Get text content
String content = configNode.getString("Property", false, true);

// Convert to string with tags
String xmlString = configNode.toString(true);

Install with Tessl CLI

npx tessl i tessl/maven-org-eclipse-jetty--jetty-xml

docs

configuration-extension.md

index.md

xml-configuration.md

xml-generation.md

xml-parser.md

tile.json