This document provides detailed information about the XQR API, including core classes, methods, and their usage.
The main class for file operations.
__init__(self, file_path: str, backup: bool = True)
Initialize with a file path.
file_path
: Path to the file to editbackup
: Whether to create a backup before modificationsquery(self, xpath: str) -> List[Element]
Query elements using XPath.
xpath
: XPath expressionset(self, xpath: str, value: str, attr: Optional[str] = None) -> bool
Set element values or attributes.
xpath
: XPath to target element(s)value
: Value to setattr
: If specified, sets this attribute instead of text contentsave(self, output_path: Optional[str] = None) -> bool
Save changes to a file.
output_path
: Optional output path (defaults to original file)Handles SVG to PDF and image format conversions.
__init__(self, input_path: str)
Initialize with input SVG path.
input_path
: Path to input SVG fileconvert_to_pdf(self, output_path: Optional[str] = None) -> str
Convert SVG to PDF.
output_path
: Output file path (defaults to input filename with .pdf)convert_to_png(self, output_path: Optional[str] = None, dpi: int = 300) -> str
Convert SVG to PNG.
output_path
: Output file pathdpi
: Resolution in DPIxqr query <file> <xpath>
xqr set <file> <xpath> <value> [--attr <attribute>]
xqr convert svg2pdf input.svg output.pdf
--backup
: Create backup before modification--no-backup
: Skip backup creation--verbose
: Show detailed output--version
: Show version and exitQuery elements using XPath.
Parameters:
xpath
: XPath expressionformat
: Output format (json/xml, default: json)Example:
curl "http://localhost:8080/api/query?xpath=//div&format=json"
Set element values.
Request Body:
{
"xpath": "//div[@class='header']",
"value": "New Header",
"attr": "class"
}
Convert between formats.
Request Body:
{
"from": "svg",
"to": "pdf",
"content": "<svg>...</svg>"
}
400 Bad Request
: Invalid input parameters404 Not Found
: Resource not found422 Unprocessable Entity
: Validation error500 Internal Server Error
: Server-side error{
"error": {
"code": "invalid_xpath",
"message": "Invalid XPath expression",
"details": "..."
}
}
API keys can be provided in the X-API-Key
header:
X-API-Key: your-api-key-here
API version is specified in the Accept
header:
Accept: application/vnd.xqr.v1+json