MCPcopy Index your code
hub / github.com/code4craft/xsoup

github.com/code4craft/xsoup @xsoup-0.3.7

Chat with this repo
repository ↗ · DeepWiki ↗ · release xsoup-0.3.7 ↗ · + Follow
411 symbols 916 edges 31 files 58 documented · 14% 2 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Xsoup

Build Status

XPath selector based on Jsoup.

Get started:

    @Test
    public void testSelect() {

        String html = "<html>

<a href='https://github.com'>github.com</a>

" +
                "<table><tr><td>a</td><td>b</td></tr></table></html>";

        Document document = Jsoup.parse(html);

        String result = Xsoup.compile("//a/@href").evaluate(document).get();
        Assert.assertEquals("https://github.com", result);

        List<String> list = Xsoup.compile("//tr/td/text()").evaluate(document).list();
        Assert.assertEquals("a", list.get(0));
        Assert.assertEquals("b", list.get(1));
    }

Performance:

Xsoup use Jsoup as HTML parser.

Compare with another most used XPath selector for HTML - HtmlCleaner, Xsoup is much faster:

Normal HTML, size 44KB
XPath: "//a"    
Run for 2000 times

Environment:Mac Air MD231CH/A 
CPU: 1.8Ghz Intel Core i5
Operation Xsoup HtmlCleaner
parse 3,207(ms) 7,999(ms)
select 95(ms) 380(ms)

Syntax supported:

XPath1.0:

Name Expression Support
nodename nodename yes
immediate parent / yes
parent // yes
attribute [@key=value] yes
nth child tag[n] yes
attribute /@key yes
wildcard in tagname /* yes
wildcard in attribute /[@*] yes
function function() part
or a | b yes since 0.2.0
parent in path . or .. no
predicates price>35 no
predicates logic @class=a or @class=b yes since 0.2.0

Function supported:

In Xsoup, we use some function (maybe not in Standard XPath 1.0):

Expression Description Standard XPath
text(n) nth text content of element(0 for all) text() only
allText() text including children not support
tidyText() text including children, well formatted not support
html() innerhtml of element not support
outerHtml() outerHtml of element not support
regex(@attr,expr,group) use regex to extract content not support

Extended syntax supported:

These XPath syntax are extended only in Xsoup (for convenience in extracting HTML, refer to Jsoup CSS Selector):

Name Expression Support
attribute value not equals [@key!=value] yes
attribute value start with [@key~=value] yes
attribute value end with [@key$=value] yes
attribute value contains [@key*=value] yes
attribute value match regex [@key~=value] yes

License

MIT License, see file LICENSE

Bitdeli Badge

Extension points exported contracts — how you extend this code

XElements (Interface)
@author code4crafter@gmail.com [4 implementers]
src/main/java/us/codecraft/xsoup/XElements.java
XPathEvaluator (Interface)
@author code4crafter@gmail.com [4 implementers]
src/main/java/us/codecraft/xsoup/XPathEvaluator.java
XElement (Interface)
@author code4crafter@gmail.com [2 implementers]
src/main/java/us/codecraft/xsoup/XElement.java

Core symbols most depended-on inside this repo

get
called by 67
src/main/java/us/codecraft/xsoup/XElement.java
select
called by 38
src/main/java/us/codecraft/xsoup/Xsoup.java
parse
called by 36
src/main/java/us/codecraft/xsoup/xevaluator/XPathParser.java
append
called by 27
src/main/java/us/codecraft/xsoup/xevaluator/FormattingVisitor.java
isEmpty
called by 23
src/main/java/us/codecraft/xsoup/XTokenQueue.java
matchChomp
called by 16
src/main/java/us/codecraft/xsoup/XTokenQueue.java
add
called by 14
src/main/java/us/codecraft/xsoup/xevaluator/CombiningEvaluator.java
convertDocument
called by 12
src/main/java/us/codecraft/xsoup/Xsoup.java

Shape

Method 358
Class 48
Interface 4
Enum 1

Languages

Java100%

Modules by API surface

src/main/java/us/codecraft/xsoup/w3c/ElementAdaptor.java41 symbols
src/main/java/us/codecraft/xsoup/XTokenQueue.java41 symbols
src/main/java/us/codecraft/xsoup/w3c/DocumentAdaptor.java32 symbols
src/main/java/us/codecraft/xsoup/xevaluator/StructuralEvaluator.java28 symbols
src/main/java/us/codecraft/xsoup/w3c/AttributeAdaptor.java28 symbols
src/main/java/us/codecraft/xsoup/xevaluator/ElementOperator.java27 symbols
src/main/java/us/codecraft/xsoup/w3c/HtmlDocumentType.java27 symbols
src/main/java/us/codecraft/xsoup/xevaluator/XPathParser.java26 symbols
src/main/java/us/codecraft/xsoup/w3c/NodeAdaptor.java19 symbols
src/test/java/us/codecraft/xsoup/XsoupTest.java15 symbols
src/test/java/us/codecraft/xsoup/w3c/W3cEvaluatorTest.java14 symbols
src/main/java/us/codecraft/xsoup/xevaluator/CombiningEvaluator.java13 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add xsoup \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page