Class XML.Inventory [ Abstract ] { XData XMLData {
Invisibility Cream 14.50 Makes you invisible Levitation Salve 23.99 Levitate yourself for up to 3 hours per application
Blork and Freen Instameal 4.95 A tasty meal in a tablet; just add water Grob winglets 3.56 Tender winglets of Grob. Just add water
} ClassMethod QueryXMLDoc(Output names As %List) As %Status { // get xml stream from the 'XData' block contained in this class Set xdata=##class(%Dictionary.CompiledXData).%OpenId($this_"||XMLData",, .sc) If $$$ISERR(sc) Quit sc Set sc=##class(%XML.XPATH.Document).CreateFromStream(xdata.Data, .xdoc) If $$$ISERR(sc) Quit sc // retrieve the first 'item' element Set sc=xdoc.EvaluateExpression("//section[1]", "item[1]", .res) // perform an action on each 'price' element (print it out) Set sc=xdoc.EvaluateExpression("//price", "text()", .res) If $$$ISERR(sc) Quit sc For i=1:1:res.Count() { If i>1 Write ", " Write res.GetAt(i).Value } // get an array of all the 'name' elements Set sc=xdoc.EvaluateExpression("//item", "name", .res) If $$$ISERR(sc) Quit sc Set key="" Do { Set dom=res.GetNext(.key) If '$IsObject(dom) Quit While dom.Read() { If dom.HasValue Set $List(names, key)=dom.Value } } While key'="" // finished Quit $$$OK } }