首页 > 解决方案 > 在 Excel 中通过 XMLFilter 过滤 XML,但 XPath 错误

问题描述

我有一个要从中过滤标题和电子邮件的 XML。

这是 XML:

<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xml:base="https://mysite/vis/_api/">
   <id>https://mysite/vis/_api/Web/GetUserById(1284)</id>
   <category term="SP.User" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
   <link rel="edit" href="Web/GetUserById(1284)" />
   <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Groups" type="application/atom+xml;type=feed" title="Groups" href="Web/GetUserById(1284)/Groups" />
   <title />
   <updated>2020-01-15T18:23:48Z</updated>
   <author>
      <name />
   </author>
   <content type="application/xml">
      <m:properties>
         <d:Id m:type="Edm.Int32">1284</d:Id>
         <d:IsHiddenInUI m:type="Edm.Boolean">false</d:IsHiddenInUI>
         <d:LoginName>i:0#.w|opmain\xespsa</d:LoginName>
         <d:Title>Alex, Johnson</d:Title>
         <d:PrincipalType m:type="Edm.Int32">1</d:PrincipalType>
         <d:Email>Alex.Johnson@stackoverflow.net</d:Email>
         <d:IsSiteAdmin m:type="Edm.Boolean">false</d:IsSiteAdmin>
         <d:UserId m:type="SP.UserIdInfo">
            <d:NameId>s-1-5-21-1377870913-3677095212-3270174719-20443</d:NameId>
            <d:NameIdIssuer>urn:office:idp:activedirectory</d:NameIdIssuer>
         </d:UserId>
      </m:properties>
   </content>
</entry>

我尝试使用 Excel 中的 XMLFILTER 函数,但我的 XPath 错误:

=XMLFILTERN(E4;"//content/title[1]")

在这种情况下,由于 Title 在内容中,我怎样才能获得正确的 xpath?

标签: excelxmlxpathfilter

解决方案


对于 Excel 中的 xPath 参数,您应该使用命名空间:

完整路径:

//content/m:properties/d:Title
//content/m:properties/d:Email

在您的特定情况下,您可以更简单地使用:

//d:Title
//d:Email

推荐阅读