1

I have the following XML (part)

<?xml version="1.0" encoding="utf-8" ?>
<definition date="2021-04-30" version="1.01">
    <changes>
        <change number="1" date="2021-04-30" description="Added .." />
        <change number="2" date="2021-04-30" description="Changes in .." />
        <change number="3" date="2021-04-30" description="Fixed .." />
        <change number="4" date="2021-05-11" description="Added " />
    </changes>
    <general>
        <styles>
            <style name="title">
                <font name="Arial" size="12" bold="true"/>
            </style>
            <style name="general">
                <font name="Courier new" size="10" bold="true" />
            </style>
            <style name="header">
                <font name="Courier new" size="10" bold="false" />
            </style>
        </styles>
    </general>

I'm using Dandraka XML-Utilities to make the XML an ExpandoObject. Which should allow me to get easily to specific values. For instance, working with the above I am able to get the Definition date and version like this:

    Dim strXML As String
    strXML = File.ReadAllText("C:\Tools\ReportDefinitions.xml")
    Dim def As Object
    def = XmlSlurper.ParseText(strXML)
    Console.WriteLine(def.date)
    Console.WriteLine(def.version)

However, I'm having a hard time getting any deeper. Tried all the ones that are commented out


'error For Each c In def.changes                    'unable to cast
'error For Each member In CType(def.changes, IDictionary(Of String, Object)) 'Invalid cast
'error For Each c In def.change                     'missing change
'error For Each c In def.changes.change             'missing change
'error For Each c In def.definition.changes.change  'missing definition
'error Console.WriteLine(def.changes.change(0).number)  'missing member
'Console.WriteLine(def.changes.changelist.numner)
For Each member In CType(def.changes, IDictionary(Of String, Object))
  Console.WriteLine(member.Key)
Next

This is what the def variable looks like Local variables

Any pointers would be much appreciated. Specifically iterating through the changes.

John
  • 87
  • 11
  • You are late-binding based on member name. So to iterate the list of changes in `def`: `For Each change As Object In def.changes.changeList`. – TnTinMn May 13 '21 at 21:40
  • Ah, @TnTinMn I see now where I went wrong. The changeList is with an uppercase L. Thought I already tried your example but must have worked with a lowercase 'l'. Thanks for pointing me in the right direction. – John May 14 '21 at 05:50

1 Answers1

1

Solved by @TnTinMn. Used the wrong casing. This is how it works

    For Each change As Object In def.changes.changeList
      Console.WriteLine(change.number)
    Next
John
  • 87
  • 11