試圖找出XPath併成功創建了一個XPathExpression,可以讓我抓取事件,但是任何嵌套的子組似乎都無法查詢,我可以獲取所有子節點在「事件」組上,但是我無法訪問的「位置名稱」字段。無法使用XPath表達式訪問子節點
我試圖找出如何讓LOCATIONNAME孩子到我的查詢
這裏是我的表達:
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
這裏是我的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">&#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.
++++
<br /><div>More info available here:
<br /><a href="http://www.chc.edu/Visit_and_Information_Sessions">http://www.chc.edu/Visit_and_Information_Sessions</a></div><div><br /></div></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"><div>Visit the Campus Ministry Office for more information.</div></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>
那麼你的問題是什麼?毫無疑問。另外,提供的XML文檔沒有任何名爲'CALENDAR_ENTERPRISE'或'EVENTS'的元素。所以,你似乎沒有提供正確的XML文檔。 請提供正確的XML文檔並定義您想要選擇哪個節點。 – 2010-08-13 01:36:51