XML - Empty nodes and child nodes

Hi all. I am trying to compare the contents of an XML file (snippet below) to the contents of a Domino Directory. The file is generated by MS Access. I’m using the NotesDOMDocument and NotesDOMNode classes, and am able to successfully process the XML. Next I want to walk the tree and, when I find an Employee node, locate and compare it to a relevant Person document.

I am running into two problems. The first is that several of the nodes are empty. Is this supposed to happen with a file of this structure?

The second is that when I do find an Employee node, I’d like to gather all the possible data points underneath it. There are always 3 data points, each with a unique, known name. Can anyone suggest a good way to do this?

I suppose my biggest issue is inexperience with the XML classes in 6. I am no newbie to LotusScript, but getting this to work right is a bear. The Designer Help file is not a lot of help.

Thanks, Keith

—XML file snippet—

<?xml version="1.0" encoding="UTF-8"?>

Afan

Joel

NRQ26Y1

Rachambault

Jared

RSQAYT7

Asheland

Gina

GGGTYA2

…

Subject: XML - Empty nodes and child nodes - Preliminary Code

OK, I came up with some preliminary code.

Is all this really necessary?

'open the XML file

Set inputStream = session.CreateStream

inputStream.Open (origXML)

If inputStream.Bytes = 0 Then

	outputStream.WriteText (origXML+" is empty"+LF)

	Goto results

End If



  'create DOM parser and process

Set domParser=session.CreateDOMParser(inputStream, outputStream)

domParser.Process



'get the document node and list of all employees

Set docNode = domParser.Document

Set employeeList = docNode.GetElementsByTagName("Employee")

outputStream.WriteText("Got the document node" + lf)



'Iterate though all employees and create objects for them

For empCount = 0 To employeeList.NumberOfEntries

	Set Node = employeeList.GetItem(empCount)

	If Not Node.IsNull Then

		If node.NodeName = "Employee" Then

			Set xmlEmployee = employeeList.GetItem(empCount)

			Set node = XMLEmployee.FirstChild

			nodeCount = -1

			Do

				If Not node.IsNull Then

					If node.NodeType = DOMNODETYPE_ELEMENT_NODE Then

						Set nodeElement = node

						Select Case nodeElement.TagName

						Case "LName" ' Last Name

							Set nodeText = nodeElement.FirstChild

							lName = nodeText.NodeValue

						Case "fName"

							Set nodeText = nodeElement.FirstChild

							fName = nodeText.NodeValue

						Case "NetID"

							Set nodeText = nodeElement.FirstChild

							netID = nodeText.NodeValue

						End Select

						Delete nodeText

					End If

				End If					

				Set node = node.NextSibling

				nodeCount = nodeCount + 1

			Loop Until nodeCount = XMLEmployee.NumberofChildNodes - 1

			outputStream.WriteText("  Employee " + fName + " " + LName + " " + netID + lf)

		End If

	End If

Next

Subject: RE: XML - Empty nodes and child nodes - Preliminary Code

There are a couple of things that aren’t necessary (like checking the nodename of a node you originally got using GetElementsByTagName – by definition, it will have the agname you asked for), but by and large, XML DOM code is going to be that verbose, yes. In fact, you are missing a node type check in your select-case – you can’t be certain that the first child of a container element node is going to be the text node you were looking for. (That’s an implementation thing, and it’s better to code for it than to be surprised on a version change. It’s been a frustrating problem with browser implementations for, well, since more than one brand has been using the DOM.)

Subject: XML - Empty nodes and child nodes

You can use GetElementByTagName(“Employee”) at the NotesDOMDocument level to get a NotesDOMNodeList containing all of the Employee element nodes. In each of those nodes, you can go through the children, or you can use GetElementsByTagName again, this time against the Employee node, to get a “list” of the desired child.

Oh, yeah – there can be blanks. They would probably represent deleted rows in the Access table.