Written by

Question Mike DeMar · Oct 16, 2017

Need example for class method within EnsLib.EDI.XML.Prop (choiceGetCount())

Hello,

I've been manipulating XML objects via Cache, but have had some difficulty understanding how to use the following method detailed within EnsLib.EDI.XML.Prop:

Method choiceGetCount(Output pCount, pDOMPath As %String, pRef As %String) As %Status 
 

From what I've read when walking through the code for this method, it appears to count a listing of repeating XML elements. However, despite my attempts to search for examples or attempts to implement this function, I am unable to do so.

Would anyone have any examples or ideas? Perhaps, at least, can someone tell me if I am using this function for its intended purpose?

Thanks,

-Mike

Comments

Mike DeMar  Oct 17, 2017 to Eduard Lebedyuk

Creating a sample EnsLib.EDI.XML.Document class:

set writer=##class(%XML.Writer).%New()
set writer.Indent=1
set status=writer.OutputToString()
set status=writer.StartDocument()
set status=writer.RootElement("root")
set status=writer.Element("RepeatingElement")
set status=writer.WriteChars("Content")
set status=writer.EndElement()
set status=writer.Element("RepeatingElement")
set status=writer.WriteChars("Content")
set status=writer.EndElement()
set status=writer.EndRootElement()
set status=writer.EndDocument()
set xmlstring = writer.GetXMLString()

set xml = ##class(EnsLib.EDI.XML.Document).%New().ImportFromString(xmlstring)

As a test, I'm trying to call inherited function "choiceGetCount()" from parent class EnsLib.EDI.XML.Prop:

write xml.choiceGetCount(1, "/root", "RepeatingElement") // outputs status of 1

So, I'm not too clear on how this function works, or if I'm using it as intended. I'm attempting to output a listing of how many times a selected XML element repeats ("RepeatingElement" in this example).  Again, here is the function signature (I think "As %Integer" was accidentally omitted for formal parameter 'Output pCount'):

Method choiceGetCount(Output pCount, pDOMPath As %String, pRef As %String) As %Status

Thanks,

-Mike

0
Eduard Lebedyuk  Oct 17, 2017 to Mike DeMar

Simplified example:

set xml = ##class(EnsLib.EDI.XML.Document).%New().ImportFromString("<root><RepeatingElement>Content</RepeatingElement><RepeatingElement>Content</RepeatingElement></root>") 
0
Mike DeMar  Oct 17, 2017 to Eduard Lebedyuk

I'm not really too clear on how to use the inherited method "choiceGetCount()" however. Would you be aware as to how, with my intentions detailed in my prior posts?

Thank you for your time.

0
Eduard Lebedyuk  Oct 17, 2017 to Mike DeMar

Not sure if choiceGetCount is a public API to do that.

You want to count a number of occurances of a particular node in some path?

0
Mike DeMar · Oct 17, 2017

You are correct, Eduard. Is there a particular function available from InterSystems that you're aware of to accomplish this?

If not, that's fine. I have something I've made myself, but was unsure if I 'reinvented the wheel' so to speak.

0
Eduard Lebedyuk  Oct 17, 2017 to Mike DeMar

XPAth can solve that, you dont need to parse XML to object in that case.

0
Mike DeMar  Oct 17, 2017 to Eduard Lebedyuk

Thanks, I'll take a look.

0
Mike DeMar · Oct 17, 2017

Publishing answer by Eduard Lebedyuk:

XPAth can solve that, you dont need to parse XML to object in that case.

0
Mike DeMar · Oct 17, 2017

Publishing answer by Eduard Lebedyuk:

XPAth can solve that, you dont need to parse XML to object in that case.

0