从 XML 文档获取标题值
嘿大家!我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有元素标题。 TITLE 位于元素内
<代码>
title = $("属性>名称", $(this)).text();
There is no element Title. TITLE is within the element <Name>
title = $("Property>Name", $(this)).text();
SP2010 有一个脚本对象模型,旨在使访问 Web 服务变得更加容易:
SP2010 has a script object model built to make accessing the webservices a lot easier:
jQuery 有一个 contains 选择器,但我不认为它有一个完全匹配的选择器。使用 contains 你可以做类似的事情
(显然你可以将所有这些粉碎在一起 - 扩展以供评论)。为了只得到“TITLE”元素(而不是说“SUBTITLE”),我认为你必须循环,例如
jQuery has a contains selector, but I don't think it has an exact-match selector. Using contains you could do something like
(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.