Written by

Question Armin Gayl · Sep 3, 2024

Count XML Elements EnsLib.EDI.XML.Document

Hello everyone,

I'm a bit confused about the number of elements in an XML object.
I have an object of the class EnsLib.EDI.XML.Document
The xsd structure ( DocType)  is an SDA Object

</container>
<Patient>
</Patient>
<Documents>
<Document>
    <DocumentNumber>0000000000000010008162012</DocumentNumber>
    <DocumentCompletionStatus><Code>IP</Code></DocumentCompletionStatus>
    <FileType>XML</FileType>
    <Stream>PD...</Stream>
</Document>
<Document>
    <DocumentNumber>0000000000000010008157893</DocumentNumber>
    <DocumentCompletionStatus><Code>IP</Code></DocumentCompletionStatus>
    <FileType>XML</FileType>
    <Stream>PD94bT....4=</Stream>
</Document>
</Documents>
</container>

 

How can I count the number of document? I have already tried to use the method choiceGetCount but get no result.

Generating an Xpath object and counting the elements did not work either.

Does anyone have an idea for me. I am sure that it is actually not difficult :-(

Kind regards

Armin

Product version: HealthShare 2024.1
$ZV: IRIS for Windows (x86-64) 2024.1 (Build 264_1U) Thu Apr 4 2024 15:26:44 EDT

Comments

Ian Pears · Sep 3, 2024

this may help

ClassMethod testCount() 
{ 
    s f=##class(%Stream.FileCharacter).%New() 
    s ff="C:\CACHEDB\ATEST.xml" d f.LinkToFile(ff) 
    s tDoc=##class(EnsLib.EDI.XML.Document).ImportFromFile(ff,,.pOutput) 
    w pOutput,! 
    q:pOutput'=1 
    s numDoc=tDoc.GetValueAt("/DocumentS/Document[*]") 
    w "numbers of Document "_numDoc,! 
}
0
Armin Gayl  Sep 4, 2024 to Ian Pears

Hi Ian,

thanks for the hint with the GetValueAt.
I had already tried this once, but discarded it due to a structural problem with the XML and did not try again after correcting the structure.  

🤯

set x = ##class(EnsLib.EDI.XML.Document).%OpenId(554)
set numdoc = x.GetValueAt("Documents(*)")
w numdoc
10

Kind regards

Armin

0