New XML and XPath built-ins for CWM

Hi everyone,
    I learned about N3 in the last W3C rules workshop, and immediately liked
it. I'm interested in exploring the possible uses of N3 and CWM to apply
rules to XML documents and other non-RDF data. 

    My first requirement was to add XPath support. I looked at Mark
Nottingham's implementation[1] (DanC, thanks for the referral), but it
didn't look like it would help me as it's restricted to HTML/XHTML and also
doesn't provide all the properties I need. So, I wrote a new implementation
by looking at Mark's code and other CWM built-ins. This first version
implements three properties (functions): selectSingleNode, selectNodes, and
evaluate. Details and source available at [2]. I'm still new to this, so I'd
appreciate any feedback and advice I can get.

    My next step is to write an XML built-in that treats XML documents and
nodes as resources (objects) rather than strings. Below are the classes and
properties I'm considering (I'm keeping as close as possible to DOM naming
for consistency):


x:XmlDocument
	x:documentElement

x:XmlNode
	x:namesapceUri
	x:localName

x:XmlElement
	owl:subclassOf x:XmlNode
	x:innerText
	x:childNodes

x:XmlAttribute
	owl:subclassOf x:XmlNode
	x:value

x:XmlNodeList
	a                rdf:Collection	
	x:firstNode?     # more work needed here


    Then, the same properties implemented in [2] will be modified to accept
an x:XmlDocument or x:XmlNode as the first item in the subject list instead
of an XML string, and to generate an x:XmlNode object rather than a string.
For example:

{ (:xml "/Order/Item") xpath:selectSingleNode :node }
 =>
{ :Test1 :result :node }

where, :xml is an x:XmlDocument and :node is x:XmlNode.


    And, a new property x:parseAsXmlDocument can be added to convert xml
strings to XmlDocuments. For example:

"<Order>...</Order>"     x:parseAsXmlDocument     :xml .


This will generate the following hierarchy of resources:

:xml = 
[  a                     x:XmlDocument;
   x:documentElement     :_g0 .
]

:_g0 =	
[  a              x:XmlNode;
   a              x:XmlElement;
   :namespaceUri  "";
   :localName     "Order";
   :innerText     "";
   :childNodes    :_g1;
]

:_g1 =
[	a		x:XmlNodeList;
	:firstNode	:_g2;
]
.....etc.



1. Does this seem like a good approach? 

2. Does CWM support computed resources (just like computed properties)? I
didn't see this mentioned in any of the documents! This feature could
provide a great extension to CWM to link it to non-RDF data sources. In my
case, although I can parse an XML document and convert it to the resources
and properties described above, I can't execute XPath expressions on it
until I load it into a DOM. 


Thanks,
Waleed

[1] http://www.mnot.net/sw/cwm_xpath/
[2] http://www.xrules.org/cwm/default.aspx

Received on Friday, 13 May 2005 06:00:28 UTC