Question
· Oct 6, 2016

%XML.TextReader - Looping Through Elements?

I have an operation which calls an external web service, returning a long XML string.

Passing the string into Excel creates a table like this:

Each row above relates to a document on a server. In Ensemble, I need to parse the XML similarly to Excel, where I can loop over each document and take various actions depending on the different values.

I created a BPL to call the operation and return the XML string, which I've converted it to an %XML.TextReader object, and I'm using a While loop to loop through each element.

I put in traces for Name, NodeType, Path and Value and examined the results through every loop:

Each row represents one loop over the %XML.TextReader object. I need one loop to encompass an entire document, instead, it's using multiple loops just to express a single document's properties (actually, multiple loops for each property). Also, not all the properties are listed (I highlighted the first row of the first screenshot, green for the fields included, red for the ones missing).

I get the feeling when Excel parses the XML, it's generating a schema automatically. I think I might need to manually create a schema for Ensemble to know how to interpret the XML - but how would I go about that? And how do I then incorporate that schema into the %XML.TextReader function?

My other idea was to loop over the %XML.TextReader as above, and on every loop where NoteType = char, piece out the last part of the PPath and set a value in a multidimensional array of strings (something like: context.Documents.k2.Value, where k2 could be a counter that starts at 1 and increments every time Name = RelayedDocument and NodeType = endelement), which I could then loop over with a For Each on context.Documents.

Any help/advice would be much appreciated.

Discussion (1)0
Log in or sign up to continue