Class XmlPattern
java.lang.Object
org.libxmq.imp.xml.XmlPattern
Streamable patterns, a port of libxml2 pattern.c (xml_pattern.c): the XPath subset used for
xs:selector and xs:field of XML Schema identity constraints (and plain patterns like "a/b",
"//c", "/a/@b", alternatives with |).
A compiled pattern can be matched against a node of the native dom (patternMatch), or, when
streamable, a stream context can be created that is fed with streamPush/streamPushAttr/streamPop
while walking a tree in document order.
Namespaces are given like libxml2 does: an array of href, prefix pairs terminated by a null href
(or null for no namespaces). The prefix xml is always bound to the xml namespace.
Compilation errors are not printed: libxml2 2.16 compiles its error messages away in pattern.c,
it only returns null. patternCompileSafe returns the error code.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intsimple pattern matchstatic final intstandard XPath patternstatic final intXPath subset for schema fieldstatic final intXPath subset for schema selector -
Method Summary
Modifier and TypeMethodDescriptionstatic XmlPatternpatternCompile(String pattern, int flags, String[] namespaces) Port of xmlPatterncompile.static intpatternCompileSafe(String pattern, int flags, String[] namespaces, XmlPattern[] pattern_out) Port of xmlPatternCompileSafe.static voidpatternFree(XmlPattern comp) Port of xmlFreePattern.static voidpatternFreeList(XmlPattern comp) Port of xmlFreePatternList.static intpatternFromRoot(XmlPattern comp) Port of xmlPatternFromRoot.static XmlStreamCtxtPort of xmlPatternGetStreamCtxt.static intpatternMatch(XmlPattern comp, XmlNode node) Port of xmlPatternMatch.static intpatternMaxDepth(XmlPattern comp) Port of xmlPatternMaxDepth.static intpatternMinDepth(XmlPattern comp) Port of xmlPatternMinDepth.static intpatternStreamable(XmlPattern comp) Port of xmlPatternStreamable.static voidstreamCtxtFree(XmlStreamCtxt stream) Port of xmlFreeStreamCtxt.static intstreamPop(XmlStreamCtxt stream) Port of xmlStreamPop. push one level from the stream.static intstreamPush(XmlStreamCtxt stream, String name, String ns) Port of xmlStreamPush.static intstreamPushAttr(XmlStreamCtxt stream, String name, String ns) Port of xmlStreamPushAttr.static intstreamPushNode(XmlStreamCtxt stream, String name, String ns, int node_type) Port of xmlStreamPushNode.static intstreamWantsAnyNode(XmlStreamCtxt stream_ctxt) Port of xmlStreamWantsAnyNode.
-
Field Details
-
XML_PATTERN_FLAG_DEFAULT
public static final int XML_PATTERN_FLAG_DEFAULTsimple pattern match- See Also:
-
XML_PATTERN_FLAG_XPATH
public static final int XML_PATTERN_FLAG_XPATHstandard XPath pattern- See Also:
-
XML_PATTERN_FLAG_XSSEL
public static final int XML_PATTERN_FLAG_XSSELXPath subset for schema selector- See Also:
-
XML_PATTERN_FLAG_XSFIELD
public static final int XML_PATTERN_FLAG_XSFIELDXPath subset for schema field- See Also:
-
-
Method Details
-
patternFree
Port of xmlFreePattern. Free up the memory allocated by `comp`- Parameters:
comp- an XSLT comp
-
patternFreeList
Port of xmlFreePatternList. Free up the memory allocated by all the elements of `comp`- Parameters:
comp- an XSLT comp list
-
streamCtxtFree
Port of xmlFreeStreamCtxt. Free the stream context- Parameters:
stream- the stream context
-
streamPush
Port of xmlStreamPush. Push new data onto the stream. Both `name` and `ns` being null means the / i.e. the root of the document. This can also act as a reset. Otherwise the function will act as if it has been given an element-node.- Parameters:
stream- the stream contextname- the current namens- the namespace name- Returns:
- -1 in case of error, 1 if the current state in the stream is a match and 0 otherwise.
-
streamPushNode
Port of xmlStreamPushNode. Push new data onto the stream. Both `name` and `ns` being null means the / i.e. the root of the document. This can also act as a reset. Different from streamPush this function can be fed with nodes of type: element-, attribute-, text-, cdata-section-, comment- and processing-instruction-node.- Parameters:
stream- the stream contextname- the current namens- the namespace namenode_type- the type of the node being pushed- Returns:
- -1 in case of error, 1 if the current state in the stream is a match and 0 otherwise.
-
streamPushAttr
Port of xmlStreamPushAttr. Push new attribute data onto the stream. Both `name` and `ns` being null means the root of the document. This can also act as a reset. Otherwise the function will act as if it has been given an attribute-node.- Parameters:
stream- the stream contextname- the current namens- the namespace name- Returns:
- -1 in case of error, 1 if the current state in the stream is a match and 0 otherwise.
-
streamPop
Port of xmlStreamPop. push one level from the stream.- Parameters:
stream- the stream context- Returns:
- -1 in case of error, 0 otherwise.
-
streamWantsAnyNode
Port of xmlStreamWantsAnyNode. Query if the streaming pattern additionally needs to be fed with text-, cdata-section-, comment- and processing-instruction-nodes. If the result is 0 then only element-nodes and attribute-nodes need to be pushed.- Parameters:
stream_ctxt- the stream context- Returns:
- 1 in case of need of nodes of the above described types, 0 otherwise. -1 on API errors.
-
patternCompileSafe
public static int patternCompileSafe(String pattern, int flags, String[] namespaces, XmlPattern[] pattern_out) Port of xmlPatternCompileSafe. Compile a pattern.- Parameters:
pattern- the pattern to compileflags- compilation flags, see XML_PATTERN_*namespaces- the prefix definitions, array of [URI, prefix] or nullpattern_out- output pattern (length 1)- Returns:
- 0 on success, 1 on error, -1 if a memory allocation failed.
-
patternCompile
Port of xmlPatterncompile. Compile a pattern.- Parameters:
pattern- the pattern to compileflags- compilation flags, see XML_PATTERN_*namespaces- the prefix definitions, array of [URI, prefix] or null- Returns:
- the compiled form of the pattern or null in case of error
-
patternMatch
Port of xmlPatternMatch. Test whether the node matches the pattern- Parameters:
comp- the precompiled patternnode- a node- Returns:
- 1 if it matches, 0 if it doesn't and -1 in case of failure
-
patternGetStreamCtxt
Port of xmlPatternGetStreamCtxt. Get a streaming context for that pattern Use streamCtxtFree to free the context.- Parameters:
comp- the precompiled pattern- Returns:
- the context or null in case of failure
-
patternStreamable
Port of xmlPatternStreamable. Check if the pattern is streamable i.e. patternGetStreamCtxt should work.- Parameters:
comp- the precompiled pattern- Returns:
- 1 if streamable, 0 if not and -1 in case of error.
-
patternMaxDepth
Port of xmlPatternMaxDepth. Check the maximum depth reachable by a pattern- Parameters:
comp- the precompiled pattern- Returns:
- -2 if no limit (using //), otherwise the depth, and -1 in case of error
-
patternMinDepth
Port of xmlPatternMinDepth. Check the minimum depth reachable by a pattern, 0 mean the / or . are part of the set.- Parameters:
comp- the precompiled pattern- Returns:
- -1 in case of error otherwise the depth,
-
patternFromRoot
Port of xmlPatternFromRoot. Check if the pattern must be looked at from the root.- Parameters:
comp- the precompiled pattern- Returns:
- 1 if true, 0 if false and -1 in case of error
-