0

我正在尝试使用 JQuery 解析 XML 文件并想要提取一些值。无论我如何去做,我似乎都无法从标签“Title”中提取值,其中标签“AlternativeCompanyName”按预期工作。

为什么会这样,我怎样才能将标题文本(我的标题)放入一个变量以供以后使用?

// JScript source code
var xml = "<VacancyList generated='2013-01-01T12:00:00' xsi:schemaLocation='http://www.easycruit.com/dtd/vacancy-list.xsd' xmlns='urn:EasyCruit' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" +
  "<Vacancy id='1234' date_start='2013-01-01' date_end='2013-02-02' reference_number=''>" +
    "<Versions>" +
      "<Version language='en'>" +
        "<Title>My Title</Title>" +
        "<TitleHeading>Title heading</TitleHeading>" +
        "<AlternativeCompanyName>my company</AlternativeCompanyName>" +
        "<ApplicationDeadline>ASAP</ApplicationDeadline>" +
        "<Location>Somewhere</Location>" +
        "<Engagement>Engagement</Engagement>" +
        "<DailyHours>Normal</DailyHours>" +
        "<Region>" +
          "<Country id='12' name='lala'>" +
            "<County id='123'>lalala</County>" +
          "</Country>" +
        "</Region>" +
        "<Categories>" +
          "<Item type='job-level' id='2345'>Department 1</Item>" +
          "<Item type='duration' id='permanent'>Permanent</Item>" +
          "<Item type='extent' id='fulltime'>Full-time</Item>" +
          "<Item type='operating-time' id='day'>Day</Item>" +
        "</Categories>" +
      "</Version>" +
    "</Versions>" +
    "<Departments>" +
      "<Department id='12345'>" +
        "<Name>Some name</Name>" +
        "<VacancyURL>http://uri.com</VacancyURL>" +
        "<ApplicationURL>http://uri.com</ApplicationURL>" +
      "</Department>" +
    "</Departments>" +
  "</Vacancy>" +
"</VacancyList>";


//Get variables id, title and AlternativeCompanyName from XML
$(xml).find("Vacancy").each(function () {
    var id = "" + $(this).attr("id") + "";

    $(this).find("Versions").each(function () {
        var title = "" + $(this).find("Title").text() + "";
        var AlternativeCompanyName = "" + $(this).find("AlternativeCompanyName").text() + "";
    });
});

我在 SharePoint 2010 平台上运行它,这意味着据我所知它是 jQuery 1.0。这可能是问题的原因吗?当我在 IE9 中调试代码时,我得到对象版本的以下值——请注意标题标签没有出现:

innerHTML   "<?XML:NAMESPACE PREFIX = [default] urn:EasyCruit NS = \"urn:EasyCruit\" /><Version language=en><TitleHeading>xxyy</TitleHeading><AlternativeCompanyName>yyyy</AlternativeCompanyName><ApplicationDeadline> ...
4

0 回答 0