使用多个选择器通过Jquery遍历XML文件

时间:2018-08-24 12:54:36

标签: javascript jquery xml web

我正在尝试基于多个选择器从XML文档中获取特定的子元素。以下是我用来查找具有匹配房间名称的所有记录的内容。请注意,我还需要根据StartDateTimeEndDateTime字段按特定的日期时间范围进行过滤。我不是网络专家,所以为了帮助解释以下内容,我将如何在SQL中做到这一点:

SELECT EventName
FROM Events
WHERE RoomName = 'Ballroom A'
and StartDateTime > '2018-08-23T08:30:00' and EndDateTime < '2018-08-23T17:00:00'
$.ajax({
  type: "GET",
  url: "data.xml",
  dataType: "xml",
  success: function(xml) {
    var nod = $(xml).find("Event RoomName:contains('Ballroom A')");
    var pNod = nod.parent();
    var name = $(pNod).find("EventName");
    alert(name.text());
  }
});

下面是XML确切格式的示例记录。我尝试链接发现并使用.has,但似乎什么也没有产生。

<GetEventsResponse>
  <StatusCode>OK</StatusCode>
  <StatusId>1000</StatusId>
  <StatusDescription>Success</StatusDescription>
  <StatusException/>
  <StatusCookie>Events came from cache</StatusCookie>
  <StatusTimeStamp>2018-08-23T09:20:09.0375049-06:00</StatusTimeStamp>
  <Events>
    <Event>
      <PropertyKey/>
      <PropertyName>HERE</PropertyName>
      <EventKey>...</EventKey>
      <EventName>EVENT 1002</EventName>
      <EventPostAs></EventPostAs>
      <GroupKey/>
      <GroupName/>
      <GroupLogoUrl/>
      <StartDateTime>2018-08-23T09:00:00</StartDateTime>
      <EndDateTime>2018-08-23T17:00:00</EndDateTime>
      <Building/>
      <RoomKey/>
      <RoomName>Ballroom A</RoomName>
      <MeetingKey/>
      <MeetingName/>
      <MeetingPostAs/>
      <MeetingType/>
      <AgreedAttendance>50</AgreedAttendance>
      <IsPostable>true</IsPostable>
      <IsExhibit>false</IsExhibit>
      <SecondaryEventPostAs/>
      <SecondaryGroupName/>
      <SecondaryRoomName/>
      <SecondaryMeetingName/>
      <SecondaryMeetingPostAs/>
      <VideoWallScreen>0</VideoWallScreen>
      <VideoWallPage>0</VideoWallPage>
      <VideoWallLine>0</VideoWallLine>
      <EventType/>
      <Status/>
      <StatusType/>
    </Event>
  </Events>
</GetEventsResponse>

任何人都可以在获取所需数据的最佳方法方面提供一些帮助。谢谢。

0 个答案:

没有答案