简体   繁体   English

无法使用XPath表达式访问子节点

[英]Can't access sub nodes with XPath expression

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. 为了弄清楚XPath,我已经成功创建了一个XPathExpression,它可以让我抓取事件,但是查询似乎无法使用任何嵌套的子组,因此我可以将Events组中的所有子级都获取,但是LocationName字段不能访问。

I am trying to figure out how to get the LocationName child into my query 我试图弄清楚如何将LocationName子项添加到我的查询中

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:

    <?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"&gt;http://www.chc.edu/Visit_and_Information_Sessions&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&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>

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. 这将从所需的注释中指示的提供的XML文档中准确选择元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM