tags:

views:

52

answers:

1

Trying to figure out XPath and I have successfully create an XPathExpression that lets me grab the events, but any nested sub groups seem to be unavailable to the query, I can get all the children on the Events group, but the LocationName field I can not access.

I am trying to figure out how to get the LocationName child into my query

Here is my expression:

Dim nav As XPathNavigator
Dim docNav As XPathDocument
docNav = New XPathDocument(New XmlNodeReader(rssDoc.DocumentElement()))

nav = docNav.CreateNavigator
'Initial XPathNavigator to start at the root.'
nav.MoveToRoot()

'Sort the Xpath query - this might be black magic'
Dim expr As XPathExpression = nav.Compile("/CALENDAR_ENTERPRISE/EVENTS")
expr.AddSort("StartDate", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Text)

Dim theEvents As XPathNodeIterator = nav.Select(expr)
While (theEvents.MoveNext())
    Dim iStartDate As XPathNodeIterator = theEvents.Current.SelectChildren("StartDate", "")
    Dim iStartTime As XPathNodeIterator = theEvents.Current.SelectChildren("StartTime", "")
End While

Here is my xml:

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
<CALENDAR_ENTERPRISE Created="8/12/2010 10:44:50 AM">
  <EVENT type="group">
    <Name type="text">Fridays After Dark Presents:  CHAT and FADD's Halloween Dance</Name>
    <Description type="text">&amp;#160;Come decked out in your favorite Halloween costume and dance the night away!</Description>
    <ContactName type="text" />
    <ContactPhone type="text" />
    <ContactEmail type="text" />
    <Department type="text">SUS</Department>
    <Categorization type="text">Undergraduate::Student Life</Categorization>
    <PrivateFlag type="text">N</PrivateFlag>
    <Highlight type="text">N</Highlight>
    <Locations type="group">
      <Location type="group">
        <LocationName type="text">Griffin's Den</LocationName>
        <SetupNotes type="text" />
      </Location>
    </Locations>
    <Resources type="group" />
    <County type="text" />
    <Country type="text">United States</Country>
    <RegistrationEnabled type="text" />
    <RegistrationMaxReg type="text" />
    <RegistrationDisplaySpaceAvail type="text" />
    <RegistrationType type="text" />
    <RegistrationTemplate type="text" />
    <InternalCustom1 type="text" />
    <InternalCustom2 type="text" />
    <InternalCustom3 type="text" />
    <InternalCustom4 type="text" />
    <InformationStatus type="text" />
    <InternalComments type="text" />
    <ExternalField1 type="text" />
    <ExternalField2 type="text" />
    <ExternalField3 type="text" />
    <ExternalField4 type="text" />
    <AllDay type="text">N</AllDay>
    <StartDate type="text">10/29/2010</StartDate>
    <StartTime type="text">10:00 PM</StartTime>
    <EndDate type="text">10/30/2010</EndDate>
    <EndTime type="text">1:00 AM</EndTime>
    <RecurType type="text">One Time</RecurType>
    <RecurDays type="text">1</RecurDays>
    <RecurEndDate type="text">10/29/2010</RecurEndDate>
    <Address1 type="text" />
    <Address2 type="text" />
    <City type="text" />
    <State type="text" />
    <Zipcode type="text" />
    <Phone type="text" />
    <InternetAddress type="text" />
    <ImportSeriesId type="text">232</ImportSeriesId>
    <ImportOccurrenceId type="text">511</ImportOccurrenceId>
    <CreatedOn type="text">7/9/2010 9:02:30 AM</CreatedOn>
    <ModifiedOn type="text">8/9/2010 2:27:00 PM</ModifiedOn>
    <AttachmentBinary type="group" />
    <ImageBinary type="group" />
    <ExternalSeriesId type="text" />
    <ExternalOccurrenceId type="text" />
    <EventOwnerName type="text">Murphy, Krista</EventOwnerName>
  </EVENT>
  <EVENT type="group">
    <Name type="text">Undergraduate Saturday Visit</Name>
    <Description type="text">Prospective students are welcomed to view a short presentation, speak with Admissions Counselors, tour the campus, and meet with representatives from Financial Aid.
++++
&lt;br /&gt;&lt;div&gt;More info available here:
&lt;br /&gt;&lt;a href="http://www.chc.edu/Visit_and_Information_Sessions"&amp;gt;http://www.chc.edu/Visit_and_Information_Sessions&amp;lt;/a&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div&amp;gt;&amp;lt;br /&gt;&lt;/div&gt;</Description>
    <ContactName type="text">Undergraduate Admissions</ContactName>
    <ContactPhone type="text">215-248-7001</ContactPhone>
    <ContactEmail type="text" />
    <Department type="text">SUS</Department>
    <Categorization type="text">Public Events||Undergraduate::Admissions</Categorization>
    <PrivateFlag type="text">N</PrivateFlag>
    <Highlight type="text">N</Highlight>
    <Locations type="group" />
    <Resources type="group" />
    <County type="text" />
    <Country type="text">United States</Country>
    <RegistrationEnabled type="text" />
    <RegistrationMaxReg type="text" />
    <RegistrationDisplaySpaceAvail type="text" />
    <RegistrationType type="text" />
    <RegistrationTemplate type="text" />
    <InternalCustom1 type="text" />
    <InternalCustom2 type="text" />
    <InternalCustom3 type="text" />
    <InternalCustom4 type="text" />
    <InformationStatus type="text" />
    <InternalComments type="text" />
    <ExternalField1 type="text" />
    <ExternalField2 type="text" />
    <ExternalField3 type="text" />
    <ExternalField4 type="text" />
    <AllDay type="text">N</AllDay>
    <StartDate type="text">10/30/2010</StartDate>
    <StartTime type="text" />
    <EndDate type="text">10/30/2010</EndDate>
    <EndTime type="text" />
    <RecurType type="text">One Time</RecurType>
    <RecurDays type="text">1</RecurDays>
    <RecurEndDate type="text">10/30/2010</RecurEndDate>
    <Address1 type="text" />
    <Address2 type="text" />
    <City type="text" />
    <State type="text" />
    <Zipcode type="text" />
    <Phone type="text" />
    <InternetAddress type="text" />
    <ImportSeriesId type="text">255</ImportSeriesId>
    <ImportOccurrenceId type="text">559</ImportOccurrenceId>
    <CreatedOn type="text">8/4/2010 9:57:25 AM</CreatedOn>
    <ModifiedOn type="text">8/4/2010 2:09:25 PM</ModifiedOn>
    <AttachmentBinary type="group" />
    <ImageBinary type="group" />
    <ExternalSeriesId type="text" />
    <ExternalOccurrenceId type="text" />
    <EventOwnerName type="text">Boccuzzi, Lori</EventOwnerName>
  </EVENT>
  <EVENT type="group">
    <Name type="text">Shriner's Hospital Service</Name>
    <Description type="text">&lt;div&gt;Visit the Campus Ministry Office for more information.&lt;/div&gt;</Description>
    <ContactName type="text" />
    <ContactPhone type="text" />
    <ContactEmail type="text" />
    <Department type="text">SUS</Department>
    <Categorization type="text">Undergraduate::Student Life</Categorization>
    <PrivateFlag type="text">N</PrivateFlag>
    <Highlight type="text">N</Highlight>
    <Locations type="group">
      <Location type="group">
        <LocationName type="text">Off-campus</LocationName>
        <SetupNotes type="text" />
      </Location>
    </Locations>
    <Resources type="group" />
    <County type="text" />
    <Country type="text">United States</Country>
    <RegistrationEnabled type="text" />
    <RegistrationMaxReg type="text" />
    <RegistrationDisplaySpaceAvail type="text" />
    <RegistrationType type="text" />
    <RegistrationTemplate type="text" />
    <InternalCustom1 type="text" />
    <InternalCustom2 type="text" />
    <InternalCustom3 type="text" />
    <InternalCustom4 type="text" />
    <InformationStatus type="text" />
    <InternalComments type="text" />
    <ExternalField1 type="text" />
    <ExternalField2 type="text" />
    <ExternalField3 type="text" />
    <ExternalField4 type="text" />
    <AllDay type="text">N</AllDay>
    <StartDate type="text">10/30/2010</StartDate>
    <StartTime type="text">12:30 PM</StartTime>
    <EndDate type="text">10/30/2010</EndDate>
    <EndTime type="text">3:30 PM</EndTime>
    <RecurType type="text">One Time</RecurType>
    <RecurDays type="text">1</RecurDays>
    <RecurEndDate type="text">10/30/2010</RecurEndDate>
    <Address1 type="text" />
    <Address2 type="text" />
    <City type="text" />
    <State type="text" />
    <Zipcode type="text" />
    <Phone type="text" />
    <InternetAddress type="text" />
    <ImportSeriesId type="text">293</ImportSeriesId>
    <ImportOccurrenceId type="text">643</ImportOccurrenceId>
    <CreatedOn type="text">8/12/2010 10:16:07 AM</CreatedOn>
    <ModifiedOn type="text">8/12/2010 10:16:07 AM</ModifiedOn>
    <AttachmentBinary type="group" />
    <ImageBinary type="group" />
    <ExternalSeriesId type="text" />
    <ExternalOccurrenceId type="text" />
    <EventOwnerName type="text">Murphy, Krista</EventOwnerName>
  </EVENT>
</CALENDAR_ENTERPRISE>
A: 

Try:

    /CALENDAR_ENTERPRISE/Event/Name 
  |
    /CALENDAR_ENTERPRISE/Event/Description
  |
    /CALENDAR_ENTERPRISE/Event/Categorization
  |
    /CALENDAR_ENTERPRISE/Event/Locations/Location/LocationName
  |
    /CALENDAR_ENTERPRISE/Event/StartDate 
  |
    /CALENDAR_ENTERPRISE/Event/StartTime
  |
    /CALENDAR_ENTERPRISE/Event/EndDate 
  |
    /CALENDAR_ENTERPRISE/Event/EndTime
  |
    /CALENDAR_ENTERPRISE/Event/ImportSeriesId 

This selects exactly the elements from the provided XML document that you indicated in your comment as wanted.

Dimitre Novatchev
I get no results going that deep from my XPathNodeIterators and not all records have any data past the Locations group. It looks like my axis is dropping and objects below the events 1st child
Mike Mc
Now that you have obviously provided a new XML document, I corrected the XPath expression accordingly. Try with the new XPath expression.
Dimitre Novatchev
I'd had assumed that but the results I get do 2 things weird. 1) any events without a location does not show up at all. 2) any data below the locationName fields seems to be inaccessible.
Mike Mc
@Mike-Mc: WHich nodes exactly (please, specify all nodes) do you want to select and do you need this to be done with a single XPath expression? Please, specify. THis is not clear from your question. I thought that you wanted just the `LocationName` elements.
Dimitre Novatchev
sorry if I am being unclear. the nodes that I want are: Name, Description, Categorization, LocationName, StartDate,StartTime, EndDate, EndTime, ImportSeriesIdthe real kicker is that I need get all events even if they do not have locations.
Mike Mc
@Mike-Mc: OK, I updated my answer -- the XPath expression now selects exactly the elements you specified.
Dimitre Novatchev
I get nothing from that, do I need to change how I retrieving the nodes? This is how I currently handle it:Dim theEvents As XPathNodeIterator = nav.Select(expr)Dim iStartDate As XPathNodeIterator = theEvents.Current.SelectChildren("StartDate", "")
Mike Mc
@Mike-Mc: I think that before using Current you must first issue MoveNext()
Dimitre Novatchev