Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

XPath query fails when "as" is a part of a path

Avatar

Level 3

XPath query:

/a/b/as

throws an error: 

{

  • results: [ ],
  • total0,
  • successfalse,
  • time0,
  • errorMessage"Encountered "as" at line 1, column 16. Was expecting one of: <IntegerLiteral> ... <DecimalLiteral> ... <DoubleLiteral> ... <StringLiteral> ... "<?" ... "<?" ... <AxisChild> ... <AxisDescendant> ... <AxisParent> ... <AxisAttribute> ... <AxisSelf> ... <AxisDescendantOrSelf> ... <AxisAncestor> ... <AxisFollowingSibling> ... <AxisPrecedingSibling> ... <AxisFollowing> ... <AxisPreceding> ... <AxisAncestorOrSelf> ... "$" ... <ElementType> ... <AttributeType> ... <SchemaElementType> ... <SchemaAttributeType> ... <OrderedOpen> ... <UnorderedOpen> ... <ElementQNameLbrace> ... <AttributeQNameLbrace> ... <PINCNameLbrace> ... <PILbrace> ... <CommentLbrace> ... <ElementLbrace> ... <AttributeLbrace> ... <TextLbrace> ... "*" ... <NCNameColonStar> ... <StarColonNCName> ... "(" ... "@" ... <DocumentLpar> ... <DocumentLparForKindTest> ... <DocumentLbrace> ... <NodeLpar> ... <CommentLpar> ... <TextLpar> ... <ProcessingInstructionLpar> ... <ElementTypeForKindTest> ... <ElementTypeForDocumentTest> ... <AttributeTypeForKindTest> ... <SchemaElementTypeForKindTest> ... <SchemaElementTypeForDocumentTest> ... <SchemaAttributeTypeForKindTest> ... <ProcessingInstructionLparForKindTest> ... <TextLparForKindTest> ... <CommentLparForKindTest> ... <NodeLparForKindTest> ... "." ... ".." ... <QNameLpar> ... "<" ... "<" ... "<!--" ... "<!--" ... <QName> ... for statement: for $v in /a/b/as return $v"

}

If I understood correctly a XPath parser treats "as" as a reserved word. In jackrabbit code I found this: 

statement = "for $v in " + statement + " return $v"; // get parser XPath parser; synchronized (parsers) { parser = (XPath) parsers.get(resolver); if (parser == null) { parser = new XPath(new StringReader(statement)); parsers.put(resolver, parser); } }

Here is a code http://grepcode.com/file/repo1.maven.org/maven2/org.apache.jackrabbit/jackrabbit-spi-commons/2.6.2/o...

In linux I've tried to execute the same XPath code using xmllint and it works:

$ xmllint --xpath '/a/b/as' test.html <as> as content </as>

Any ideas what's wrong with jackrabbit when "as" is part of a path?

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 10

Here is what I found:

I have a folder in DAM named xpath. Like this:

/content/dam/pdf/xtype

WHen i search via xpath - i get a result:

[img]XPATH1.png[/img]

Now when i do the same search on this path:

/content/dam/as/xtype

[img]xpath2.png[/img]

The error does occur. Look like you are correct - xpath and using as in the path does result in an error. 

So either do 1 of 2 things:

1 - avoid using as in path

2 - try using JCR SQL to search when you use as in path

JCR SQL works:

[img]xpath3.png[/img]

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

Here is what I found:

I have a folder in DAM named xpath. Like this:

/content/dam/pdf/xtype

WHen i search via xpath - i get a result:

[img]XPATH1.png[/img]

Now when i do the same search on this path:

/content/dam/as/xtype

[img]xpath2.png[/img]

The error does occur. Look like you are correct - xpath and using as in the path does result in an error. 

So either do 1 of 2 things:

1 - avoid using as in path

2 - try using JCR SQL to search when you use as in path

JCR SQL works:

[img]xpath3.png[/img]