xqr

API Reference

This document provides detailed information about the XQR API, including core classes, methods, and their usage.

Core Classes

FileEditor

The main class for file operations.

Methods

__init__(self, file_path: str, backup: bool = True)

Initialize with a file path.

query(self, xpath: str) -> List[Element]

Query elements using XPath.

set(self, xpath: str, value: str, attr: Optional[str] = None) -> bool

Set element values or attributes.

save(self, output_path: Optional[str] = None) -> bool

Save changes to a file.

SVGConverter

Handles SVG to PDF and image format conversions.

Methods

__init__(self, input_path: str)

Initialize with input SVG path.

convert_to_pdf(self, output_path: Optional[str] = None) -> str

Convert SVG to PDF.

convert_to_png(self, output_path: Optional[str] = None, dpi: int = 300) -> str

Convert SVG to PNG.

Command Line Interface

Basic Commands

Query

xqr query <file> <xpath>

Set Value

xqr set <file> <xpath> <value> [--attr <attribute>]

Convert SVG to PDF

xqr convert svg2pdf input.svg output.pdf

Global Options

REST API

Endpoints

GET /api/query

Query elements using XPath.

Parameters:

Example:

curl "http://localhost:8080/api/query?xpath=//div&format=json"

POST /api/set

Set element values.

Request Body:

{
  "xpath": "//div[@class='header']",
  "value": "New Header",
  "attr": "class"
}

POST /api/convert

Convert between formats.

Request Body:

{
  "from": "svg",
  "to": "pdf",
  "content": "<svg>...</svg>"
}

Error Handling

Common Error Codes

Error Response Format

{
  "error": {
    "code": "invalid_xpath",
    "message": "Invalid XPath expression",
    "details": "..."
  }
}

Rate Limiting

Authentication

API keys can be provided in the X-API-Key header:

X-API-Key: your-api-key-here

Versioning

API version is specified in the Accept header:

Accept: application/vnd.xqr.v1+json

Deprecation Policy