Retrieving a element attribute from a data source from other view?

K

kfrost

Hello,

I have two views, Main and TripDetails. The main has a repeating table that
is populated by a secondary data connection called Trips.

Users select a trip by clicking a button and they get taken to the
TripDetails view which has fields populated by a data connection to Sql
called main.

For certain situations, while in trip details, I need to access via code
nodes in the Trips data connection.

I've been trying to use the following to work with no luck.

Dim objTripsNode As IXMLDOMNode = thisXDocument.DataObjects("Trips").DOM

Dim objTripsElem As IXMLDOMElement = objTripsNode.selectSingleNode("//Trips")

Dim strID As String = objTripsElem.getAttribute("TripID")

The first line creates an object with the data from Trips. However, the
second line does nothing. objTripsElem keeps a value of nothing. If I look
at the xml value in the objTripsNode object, I see the TripID attribute I'm
looking for but I just can't figure out how to access it.

Any ideas?
 
S

Scott L. Heim [MSFT]

Hi Kris,

There are a couple of items you are missing - in order to "walk the DOM"
you will need to set some Namespace information as well.

I setup a sample SQL table named Trips with simply TripID and TripName
fields. I then added this as a secondary datasource so when I look at this
in the Data Source Task Pane, it appears as:

- myFields
- dataFields
- d:Trips
TripID
TripName

I only give you this to simply provide some reference for the following
code - here is what I have on a button:

Dim objTripsNode As IXMLDOMDocument3
objTripsNode = DirectCast(thisXDocument.GetDOM("Trips"),
IXMLDOMDocument3)

objTripsNode.setProperty("SelectionNamespaces", _

"xmlns:dfs=""http://schemas.microsoft.com/office/infopath/2003/dataFormSolut
ion"" " & _

"xmlns:d=""http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"
"")

Dim objTripsElem As IXMLDOMNode =
objTripsNode.selectSingleNode("dfs:myFields/dfs:dataFields/d:Trips")

I hope this helps in what you need!

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top