Real Studio: finding position of XQL results in original XmlDocument

243 Views Asked by At

I have the following XML (stored in an XmlDocument):

<root>
  <row>
    <elem>Timestamp</elem>
    <elem>ERB.CHW.BTU_CV</elem>
    <elem>ERB.CHW.BTU1_CV</elem>
    <elem>ERB.HW.BTU_CV</elem>
    <elem>ERB.HW.BTU1_CV</elem>
    <elem>ERB.KW.DEMAND_CV</elem>
    <elem>ERB.KWH.MT_CV</elem>
    <elem></elem>
  </row>
  <row>
    <elem>2011/09/30 11:21:13.9062</elem>
    <elem>2.307609E+09</elem>
    <elem>1880067</elem>
    <elem>1.068635E+08</elem>
    <elem>1340.386</elem>
    <elem>448.8</elem>
    <elem>1427723</elem>
    <elem></elem>
  </row>
</root>

I am working with this query:

Dim results As XmlNodeSet = myDoc.xql("/*/row[1]/elem[normalize-space()]")

...which returns the XmlNodeSet back to me that I would expect:

<elem>Timestamp</elem>
<elem>ERB.CHW.BTU_CV</elem>
<elem>ERB.CHW.BTU1_CV</elem>
<elem>ERB.HW.BTU_CV</elem>
<elem>ERB.HW.BTU1_CV</elem>
<elem>ERB.KW.DEMAND_CV</elem>
<elem>ERB.KWH.MT_CV</elem>

However, I would like to know where in the source XML this XmlNodeSet occurs (so that I can use a highlighting function -- which takes a starting point and a length, both integers -- to highlight these results in the original document).

From what I can tell, there's no obvious way to compare my result NodeSet against the original XmlDocument (and somehow get the position of those elements within that source document). I've experimented with some ideas and thus far, the only one I can think of is the following horrible process:

  1. Run an XSLT against the source document -- using my original XPath -- that puts extraneous markup in the original source document (e.g., <elem highlight="true">ERB.KWH.MT_CV</elem>).
  2. Use regular expressions within RS to figure out the positioning of the elements that contain this markup.
  3. Output a version of the document that (a) has the markup removed and (b) highlights the text in those positions.

Yuck. Can anyone think of a better way?

1

There are 1 best solutions below

0
On

See the source code of XPath Visualizer -- you can download it at:

http://www.huttar.net/dimitre/XPV/TopXML-XPV.html

The relevant code is in the XSLT stylesheet.

References