XML schema type definition for XPath values?

I have an XML file in which I have an attribute whose value will be XPath to search for content in another set of XML files.

Example:

<?xml version="1.0" encoding="utf-8"?>
<Root>
  <IterestingNode Value="/html/head/title"/>
</Root>

This file can be checked using XSD. I am currently simply confirming that the attribute value is a string, but I would like to verify that this is a syntactically valid XPath value.

Is there an XML schema definition for XPath values?

+5
source share
4 answers

There is no XSD data type for XPATH expression.

The best you could do is use xsd:restrictionwith xsd:pattern, which uses the regex pattern to verify that the string value is an XPATH expression.

- :

<xsd:simpleType name="XPathValueType">
  <xsd:restriction base="xsd:string">
    <xsd:pattern value="**PUT IN SOME REGEX PATTERN TO VERIFY THE STRING IS AN XPATH EXPRESSION**"/>
  </xsd:restriction>
</xsd:simpleType>

, , XPATH .

+3

, xpath - , XML. : ht tp://www.w3.org/TR/xpath/

0

anyURI XPointer

XPointer:

<?xml version="1.0" encoding="utf-8"?>
<Root>
  <IterestingNode Value="doc.xml#xpointer(/html/head/title)"/>
</Root>
0

, , redben, (, , , , xslt xsd), xslt xsd, xsd xpath:

<xs:simpleType name="expression">
    <xs:annotation>
        <xs:documentation>
            An XPath 2.0 expression.
        </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:token">
        <xs:pattern value=".+"/>
    </xs:restriction>
</xs:simpleType>

, , , , .

0

All Articles