Ensemble VDOC rule - how to address document property using "Property Path"?
this is catching me all the time, again and again...
Haven't worked with XML VDOC for some time, I can't figure out, what is the correct way of using Property path. Can someone please help me to refresh my memory.
Simple example: I have a class called Body, with Value and Topic properties. I created a XML Schema for this class and imported it into Ensemble. So i have a category called message, with Body as DocType structure and Name and Topic properties of Body complex type ($2:Value and $2:Topic are element names)
My rule looks this way:

However, the rule is ALWAYS evaluated as TRUE. but TRACE element shows null value for "value".
I also did a programming test using this code:
s vDoc=##class(EnsLib.EDI.XML.Document).ImportFromString("<Body><Topic>Temperature</Topic><Value>30</Value></Body>",.sc)
w !,sc
w !,vDoc.GetValueAt("/Body/Value")
w !,vDoc.GetValueAt("$2:Value")
but only /Body/Value worked fine (the DOM path) and returned 30, the $2:Value returned empty string.
What am I missing?
Comments
It looks as for $-notation one needs some DocType to be available, at least this is what %objlasterror tells.
Using [] you might get what you expect.
ENSEMBLE>write !,vDoc.GetValueAt("$1")
ENSEMBLE>write %objlasterror
0 ñ<Ens>ErrGeneral:Can't evaluate property path because DocType is not set
ENSEMBLE,e^zpropParsePath+2^EnsLib.EDI.XML.Prop.1^1-e^zpropGetValueAt+3^EnsLib.EDI.XML.Prop.1^1.e^zGetValueAt+16^EnsLib.EDI.XML.Document.1^1e^^^0
Variants with []-notation:
ENSEMBLE>write !,vDoc.GetValueAt("/Body/[2]")
30
ENSEMBLE>write !,vDoc.GetValueAt("/[1]/[2]")
30
Thank you Markus for hint,
I have modified the code to read this way:
#dim vDoc as EnsLib.EDI.XML.Document=##class(EnsLib.EDI.XML.Document).ImportFromString("<Body><Topic>Temperature</Topic><Value>30</Value></Body>",.sc)
s vDoc.DocType="message:Body"
s vDoc.DocTypeCategory="message"
w !,vDoc.GetValueAt("/Body/Value")
w !,vDoc.GetValueAt("Value",,.sc)
if $$$ISERR(sc) d $System.Status.DisplayError(sc)
but it throws :
ERROR <Ens>ErrGeneral: Can't evaluate DOM path '/Body/$2:Value' because xsd_2:Topic in /Body/xsd_2:Value is not an element, instead this node is a 'unknown' node.
this drives me mad...
BTW: you're still using DOM way and not property path way of retrieving data.
got it. I was missing xmlns declaration.
this
#dim vDoc as EnsLib.EDI.XML.Document=##class(EnsLib.EDI.XML.Document).ImportFromString("<Body xmlns=""http://tempuri.org/ISC/JBH""><Topic>Temperature</Topic><Value>30</Value></Body>",.sc)
works as expected.