从 XML 文档获取标题值

发布于 2024-10-15 06:35:01 字数 2711 浏览 1 评论 0原文

嘿大家!我有一个 jquery 可以在共享点服务器上进行查询&以 XML 文档的形式获取结果,如下所示:

<?xml version="1.0" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <QueryResponse xmlns="urn:Microsoft.Search">
      <QueryResult>
        <ResponsePacket xmlns="urn:Microsoft.Search.Response">
          <Response>
            <Range>
              <StartAt>1</StartAt>
              <Count>1</Count>
              <TotalAvailable>1</TotalAvailable>
              <Results>
                <Document xmlns="urn:Microsoft.Search.Response.Document">
                  <Action>
                    <LinkUrl>http://ishaan1519:1234/Lists/Discussions/where are 401k benefit investment prospectus</LinkUrl>
                  </Action>
                  <Properties xmlns="urn:Microsoft.Search.Response.Document.Document">
                    <Property>
                      <Name>TITLE</Name>
                      <Type>String</Type>
                      <Value>where are 401k benefit investment prospectus</Value>
                    </Property>
                    <Property>
                      <Name>PATH</Name>
                      <Type>String</Type>
                      <Value>http://ishaan1519:1234/Lists/Discussions/where are 401k benefit investment prospectus</Value>
                    </Property>
                  </Properties>
                </Document>
              </Results>
            </Range>
            <Status>SUCCESS</Status>
          </Response>
        </ResponsePacket>
      </QueryResult>
    </QueryResponse>
  </soap:Body>
</soap:Envelope>

我需要使用标题和内容填充文本字段(#output)。链接路径 使用此函数

$(xData.responseXML).find("QueryResult").each(function () {
    var x = $("<xml>" + $(this).text() + "</xml>");

    x.find("Document").each(function () {
        url = $("Action>LinkUrl", $(this)).text();

        title = $("Title", $(this)).text();

        $("#output").append("title: " + title + " - LinkUrl: " + url);
    });

我可以获得 LinkUrl 但标题为 null 请帮我用 title 填充文本字段。来自

<Property>
    <Name>TITLE</Name>
    <Type>String</Type>
    <Value>where are 401k benefit investment prospectus</Value>
</Property>

提前致谢!

hey all ! i have a jquery that hits a Query on the sharepoint server & fetches the result in the form of XML document that look like :

<?xml version="1.0" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <QueryResponse xmlns="urn:Microsoft.Search">
      <QueryResult>
        <ResponsePacket xmlns="urn:Microsoft.Search.Response">
          <Response>
            <Range>
              <StartAt>1</StartAt>
              <Count>1</Count>
              <TotalAvailable>1</TotalAvailable>
              <Results>
                <Document xmlns="urn:Microsoft.Search.Response.Document">
                  <Action>
                    <LinkUrl>http://ishaan1519:1234/Lists/Discussions/where are 401k benefit investment prospectus</LinkUrl>
                  </Action>
                  <Properties xmlns="urn:Microsoft.Search.Response.Document.Document">
                    <Property>
                      <Name>TITLE</Name>
                      <Type>String</Type>
                      <Value>where are 401k benefit investment prospectus</Value>
                    </Property>
                    <Property>
                      <Name>PATH</Name>
                      <Type>String</Type>
                      <Value>http://ishaan1519:1234/Lists/Discussions/where are 401k benefit investment prospectus</Value>
                    </Property>
                  </Properties>
                </Document>
              </Results>
            </Range>
            <Status>SUCCESS</Status>
          </Response>
        </ResponsePacket>
      </QueryResult>
    </QueryResponse>
  </soap:Body>
</soap:Envelope>

i need to populate the text field (#output ) with title & link path
using this function

$(xData.responseXML).find("QueryResult").each(function () {
    var x = $("<xml>" + $(this).text() + "</xml>");

    x.find("Document").each(function () {
        url = $("Action>LinkUrl", $(this)).text();

        title = $("Title", $(this)).text();

        $("#output").append("title: " + title + " - LinkUrl: " + url);
    });

i can get the LinkUrl but the title is null
please help me out to populate the textfield with title . from

<Property>
    <Name>TITLE</Name>
    <Type>String</Type>
    <Value>where are 401k benefit investment prospectus</Value>
</Property>

Thanks in Advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

屌丝范 2024-10-22 06:35:01

没有元素标题。 TITLE 位于元素

<代码>
title = $("属性>名称", $(this)).text();

There is no element Title. TITLE is within the element <Name>


title = $("Property>Name", $(this)).text();

毁梦 2024-10-22 06:35:01

SP2010 有一个脚本对象模型,旨在使访问 Web 服务变得更加容易:

var clientContext = new SP.ClientContext("http://ishaan1519:1234/");
var list = clientContext.get_web().get_lists().getByTitle('/Discussions');   
var q = "<View><ViewFields><FieldRef Name='Title'/><FieldRef Name='Path'/></ViewFields></View>";    
camlQuery.set_viewXml(q);
var listItems = list.getItems(camlQuery);
clientContext.load(listItems, 'Include(Title,Path)'); 
clientContext.executeQueryAsync(function(sender, args) {
    var listEnumerator = listItems.getEnumerator();
    while (listEnumerator.moveNext())  {
        var title = listEnumerator.get_current().get_item("Title");
        var path = listEnumerator.get_current().get_item("Path");
        ///do your stuff
    }
}, function(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}); 

SP2010 has a script object model built to make accessing the webservices a lot easier:

var clientContext = new SP.ClientContext("http://ishaan1519:1234/");
var list = clientContext.get_web().get_lists().getByTitle('/Discussions');   
var q = "<View><ViewFields><FieldRef Name='Title'/><FieldRef Name='Path'/></ViewFields></View>";    
camlQuery.set_viewXml(q);
var listItems = list.getItems(camlQuery);
clientContext.load(listItems, 'Include(Title,Path)'); 
clientContext.executeQueryAsync(function(sender, args) {
    var listEnumerator = listItems.getEnumerator();
    while (listEnumerator.moveNext())  {
        var title = listEnumerator.get_current().get_item("Title");
        var path = listEnumerator.get_current().get_item("Path");
        ///do your stuff
    }
}, function(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}); 
你穿错了嫁妆 2024-10-22 06:35:01

jQuery 有一个 contains 选择器,但我不认为它有一个完全匹配的选择器。使用 contains 你可以做类似的事情

    x.find("Document").each(function () {
        url = $("Action>LinkUrl", $(this)).text();

        // find the Name element that contains TITLE
        var $nameTitle = $(this).find("Name:contains('TITLE')");
        // find the containing Property element
        var $property = $nameTitle.closest('Property');
        // find the Value in that Property
        var $value = $property.find('Value');
        // and read text
        var title = $value.text();

(显然你可以将所有这些粉碎在一起 - 扩展以供评论)。为了只得到“TITLE”元素(而不是说“SUBTITLE”),我认为你必须循环,例如

        var title = null;
        $(this).find('Name').each(function() {
          var $name = $(this);
          if ($name.text() == 'TITLE') {
            title = $name.closest('Property').find('Value').text();
            return false;
          }
        });

jQuery has a contains selector, but I don't think it has an exact-match selector. Using contains you could do something like

    x.find("Document").each(function () {
        url = $("Action>LinkUrl", $(this)).text();

        // find the Name element that contains TITLE
        var $nameTitle = $(this).find("Name:contains('TITLE')");
        // find the containing Property element
        var $property = $nameTitle.closest('Property');
        // find the Value in that Property
        var $value = $property.find('Value');
        // and read text
        var title = $value.text();

(obviously you can smash all of those together - expanded for comments). To get just the 'TITLE' element (and not say 'SUBTITLE') I think you'd have to loop, e.g.

        var title = null;
        $(this).find('Name').each(function() {
          var $name = $(this);
          if ($name.text() == 'TITLE') {
            title = $name.closest('Property').find('Value').text();
            return false;
          }
        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文