Skip to main content

The ShowMenu Method

Now we add a new method, ShowMenu, that reads the XML source document and displays an HTML menu based on its contents:

ClassMethod ShowMenu(filename As %String)
{
    Set sc = ##class(%XML.TextReader).ParseFile(filename,.reader)
    If ($$$ISOK(sc)) {
        While (reader.Read()) {
            If ((reader.NodeType = "element") &&
                    (reader.LocalName = "item")) {
                Write reader.Value,"<MENU>",!
                If (reader.MoveToAttributeName("caption")) {
                    Write "<LI>",reader.Value,!
                }
            }
            ElseIf ((reader.NodeType = "endelement") &&
                    (reader.LocalName = "item")) {
                Write reader.Value,"</MENU>",!
            }
        }
    }
    Else {
        // error
        Do $system.OBJ.DisplayError(sc)
    }
}
FeedbackOpens in a new tab