The SWRLTab XML Built-In Library is one of the SWRLTabBuiltInLibraries. It defines built-ins that can be used to query XML documents. (A07)
Warning: this is a relatively primitive library at the moment and only supports simple XML documents. (A61)
XPath support will be available shortly. (A0P)
The built-ins in this library are defined by the OWL XML Ontology. The standard alias is swrlxml. A copy of this file can be found the standard Protege-OWL repositories, and can be imported through the 'Import Ontology' option in the Metadata tab. (A0J)
The OWL mapping ontology contains classes that can be used to hold the contents of an XML document. It consists of three classes: XMLDocument, XMLElement, and XMLAttribute. (A0S)
The XMLDocument class contains a hasRootElement property with a range of a single XMLElement that defines the root element of an XML document. It also contains a hasElements property that contains all the XML elements in the document. (A0Q)
The XMLElement class contains an hasName string property defining the name of the XML element, a hasSubElements property that contains sub-elements of the element, a hasAttributes property containing any attributes associated with the XML element, and a hasContent property defining the content of element. Namespaces and prefixes are defined by hasNamespacePrefix and hasNamespaceURI properties. (A0R)
The XMLAttribute class contains a hasName property defining the name of the XML attribute, and a hasValue property that contains a value for the attribute. As with the XMLElement class, namespaces and prefixes for the attribute are defined by hasNamespacePrefix and hasNamespaceURI properties. (A0I)
The following built-in is defined by this library: (A0K)
- makeXMLDocument Returns true if the first argument is an individual of class swrlxml:XMLDocument that corresponds to an OWL XML representation of the contents of the XML document named by the second URL argument. If the first argument is unbound, bind it to the individual that corresponds to this document. (A08)
Examples (A0L)
The following examples show how this built-in can be with use in SQWRL queries to examine the structure of an XML document. These queries can be executed using either the SQWRLQueryTab or the SQWRLQueryAPI. (A0M)
Return the name of the root element in an XML document contained in a local file: (A0N)
- swrlxml:makeXMLDocument(?d, "file://Development/SWRL/xml/SWRLTest.xml") ^ swrlxml:hasRootElement(?d, ?root) ^ swrlxml:hasName(?root, ?name) -> sqwrl:select(?name) (A0A)
Return the name of the root element in an XML document on the web: (A0N)
- swrlxml:makeXMLDocument(?d, "http://swrl.stanford.edu/xml/SWRLTest.xml") ^ swrlxml:hasRootElement(?d, ?root) ^ swrlxml:hasName(?root, ?name) -> sqwrl:select(?name) (A0A)
Assuming at least one swrlxml:makeXMLDocument is present in a set of active queries, we can then express additional queries without repeating this built-in. (A0B)
List the names of all elements in a document: (AMI)
- swrlxml:XMLDocument(?d) ^ swrlxml:hasElements(?d, ?e) ^ swrlxml:hasName(?e, ?name) → sqwrl:selectDistinct(?name) (AMJ)
List all the names of the sub-elements of the root element in an XML document: (A0C)
- swrlxml:XMLDocument(?d) ^ swrlxml:hasRootElement(?d, ?root) ^ swrlxml:hasSubElements(?root, ?e) ^ swrlxml:hasName(?e, ?name) -> sqwrl:select(?name) (A0D)
List all the names of the sub-elements of an element named "Sites" in an XML document: (A0E)
- swrlxml:XMLElement(?esites) ^ swrlxml:hasName(?esites, "Sites") ^ swrlxml:hasSubElements(?esites,?e) ^ swrlxml:hasName(?e, ?name) -> sqwrl:select(?name) (A0F)