Skip to content

Releases: reclaimprotocol/xpath-go

v1.4.0: Unified Evaluator & 100% Test Compatibility

24 Dec 17:16

Choose a tag to compare

Refactor: Modularize evaluator, unified parser, and 100% test compatibility

  • Split function_parser.go into expressions.go, function_eval.go, and function_parser.go
  • Implement unified ExpressionEvaluator for all predicate types
  • Add Debug flag to Options for detailed execution tracing
  • Fix NodeSet truthiness and text node dot predicate parsing
  • Fix nested predicate parsing bug in FunctionParser
  • Achieve 100% pass rate on comprehensive test suite

v1.3.0

18 Aug 15:17

Choose a tag to compare

XPath Go v1.3.0

🎯 High-Compatibility XPath Library for Go

This release brings comprehensive XPath functionality with strong compatibility and precise node location tracking.

✨ Highlights

  • High Compatibility: Strives for close compatibility with web standards and jsdom
  • Location Tracking: Precise character positioning in source HTML/XML
  • Production Ready: Comprehensive error handling and performance optimization

What's Changed

Changelog

Other Changes

Full Changelog: v1.2.0...v1.3.0

v1.2.0

18 Aug 14:08

Choose a tag to compare

πŸš€ New Features

  • ✨ ContentsOnly Extraction Mode: Added new option for XPath queries that allows extracting either:
    • Full elements (including tags): <div>content</div>
    • Content only (inner content): content
  • πŸ“„ CLI Support: New --contents-only flag for command-line usage
  • 🎯 100% Compatibility: Maintained full test compatibility across 132+ test cases

πŸ“‹ Documentation

  • Added comprehensive XPath 2.0 compatibility analysis document
  • Complete API documentation for contentsOnly functionality
  • Usage examples and implementation notes

πŸ”§ Technical Improvements

  • Enhanced HTML parser with precise content boundary tracking
  • Added ContentStart/ContentEnd fields to Result struct
  • Integrated contentsOnly tests into main comprehensive test suite
  • Support for dual-mode extraction across all XPath expressions

πŸ“– API Changes

New Options

type Options struct {
    IncludeLocation bool
    OutputFormat    string
    ContentsOnly    bool  // New: Extract only inner content between tags
}

New Result Fields

type Result struct {
    // ... existing fields
    ContentStart int // New: Start of inner content (after opening tag)
    ContentEnd   int // New: End of inner content (before closing tag)
}

Usage Example

// Extract full elements (default)
results, _ := xpath.QueryWithOptions("//div", html, xpath.Options{
    ContentsOnly: false,
})

// Extract only inner content
results, _ := xpath.QueryWithOptions("//div", html, xpath.Options{
    ContentsOnly: true,
})

Perfect for use cases where you need to extract text content without HTML tags while maintaining precise position tracking for all extraction modes.

v1.1.0

18 Aug 13:32

Choose a tag to compare

XPath Go v1.1.0

🎯 High-Compatibility XPath Library for Go

This release brings comprehensive XPath functionality with strong compatibility and precise node location tracking.

✨ Highlights

  • High Compatibility: Strives for close compatibility with web standards and jsdom
  • Location Tracking: Precise character positioning in source HTML/XML
  • Production Ready: Comprehensive error handling and performance optimization

What's Changed

Changelog

Other Changes

Full Changelog: v1.0.0...v1.1.0

v1.0.0

17 Aug 22:49

Choose a tag to compare

🎯 xpath-go v1.0.0 - Production Ready

A high-performance XPath library for Go with 100% jsdom compatibility and precise location tracking.

✨ Key Features

  • 🎯 100% jsdom Compatibility - Perfect matching with jsdom's XPath evaluation (76/76 tests passing)
  • πŸ“ Precise Location Tracking - Character-level positioning in source HTML/XML
  • ⚑ High Performance - Optimized evaluation engine with compiled XPath support (~2x speedup)
  • πŸ”§ Production Ready - Comprehensive error handling and extensive testing
  • πŸ“¦ Zero Dependencies - Pure Go implementation

πŸš€ Quick Start

package main

import (
    "fmt"
    "log"
    "github.com/reclaimprotocol/xpath-go"
)

func main() {
    html := `<div id="content" class="main">Hello World</div>`
    
    // Simple query
    results, err := xpath.Query("//div[@id='content']", html)
    if err != nil {
        log.Fatal(err)
    }
    
    for _, result := range results {
        fmt.Printf("Found: %s at position %d-%d\n", 
            result.TextContent, result.StartLocation, result.EndLocation)
    }
}

⚑ Performance Optimization

Use compiled XPath for repeated queries:

// Compile once
compiled, err := xpath.Compile("//div[@class='item']")

// Use multiple times (2x faster)
for _, doc := range documents {
    results, err := compiled.Evaluate(doc)
    // Process results...
}

πŸ“Š Compatibility Status

Current jsdom compatibility: 100% (76/76 tests passing)

Feature Category Status Tests
Basic Selection βœ… 100% 12/12
Attribute Queries βœ… 100% 8/8
Text Functions βœ… 100% 15/15
Position Functions βœ… 100% 8/8
Axes Navigation βœ… 100% 18/18
Complex Predicates βœ… 100% 12/12
String Functions βœ… 100% 3/3

πŸ“š Documentation

πŸ”§ Installation

go get github.com/reclaimprotocol/xpath-go

πŸ§ͺ Testing

# Go tests
go test ./...

# Compatibility tests (requires Node.js)
cd tests && npm install && npm test

πŸŽ‰ Production Ready: This library is actively used in production and maintains 100% compatibility with jsdom XPath evaluation.

🀝 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

Full Changelog: https://github.com/reclaimprotocol/xpath-go/commits/v1.0.0