相关疑难解决方法(0)

如何使用XPath忽略名称空间

我的目标是使用XPath从具有多个名称空间的多个xml文件中提取某些节点.只要我知道名称空间URI,一切正常.命名空间名称本身保持不变,但模式(XSD)有时是客户端生成的,即我不知道.然后我基本上有三种选择:

  1. 只使用一个模式用于命名空间,希望没有出错(我能确定吗?)

  2. 获取文档的子节点并查找带有命名空间URI的第一个节点,希望它在那里并只使用URI,希望它是正确的.可能由于多种原因而出错

  3. 不知何故告诉xpath:"看,我不关心命名空间,只需找到具有此名称的所有节点,我甚至可以告诉您命名空间的名称,而不是URI".这就是问题......

这不是许多"我的xpath表达不起作用的重复,因为我不知道命名空间感知" 这里这里发现的问题.我知道如何使用命名空间感知.只是没有如何摆脱它.

xml xpath namespaces xml-namespaces

96
推荐指数
3
解决办法
8万
查看次数

SelectNodes无法处理stackoverflow Feed

我正在尝试在我的RSS阅读器中添加对stackoverflow提要的支持,但SelectNodesSelectSingleNode没有任何效果.这可能与我还不了解的ATOM和xml命名空间有关.

我已经通过从feed标签中删除所有属性来实现它,但这是一个黑客,我想正确地做到这一点.那么,你如何使用带有原子馈送的SelectNodes

这是一个饲料片段.

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:thr="http://purl.org/syndication/thread/1.0">

<title type="html">StackOverflow.com - Questions tagged: c</title>
<link rel="self" href="http://stackoverflow.com/feeds/tag/c" type="application/atom+xml" />
<subtitle>Check out the latest from StackOverflow.com</subtitle>
<updated>2008-08-24T12:25:30Z</updated>
<id>http://stackoverflow.com/feeds/tag/c</id>
<creativeCommons:license>http://www.creativecommons.org/licenses/by-nc/2.5/rdf</creativeCommons:license>


 <entry>
   <id>http://stackoverflow.com/questions/22901/what-is-the-best-way-to-communicate-with-a-sql-server</id>
   <title type="html">What is the best way to communicate with a SQL server?</title>
   <category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="c" /><category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="c++" /><category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="sql" /><category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="mysql" /><category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="database" />  
   <author><name>Ed</name></author>
   <link rel="alternate" href="http://stackoverflow.com/questions/22901/what-is-the-best-way-to-communicate-with-a-sql-server" />
   <published>2008-08-22T05:09:04Z</published>
   <updated>2008-08-23T04:52:39Z</updated>
   <summary type="html">&lt;p&gt;I am going to …
Run Code Online (Sandbox Code Playgroud)

.net c# rss atom-feed

15
推荐指数
2
解决办法
8028
查看次数

带命名空间的XML的XPath

我有一个带有各种命名空间的xml,我想使用它来查询.SelectNodes(string xPath)

我注意到的问题是,只要我拥有所有这些名称空间,xPath查询就不会返回任何内容.

  1. 无论如何告诉XmlDocument.SelectNodes忽略这些命名空间,只是给我正确的元素(我查询的元素似乎没有名称空间前缀)?

  2. 如果有,有谁可以请我提供一个如何做的例子?我在查询节点之前/当我应该定义什么?

谢谢您的帮助.

更正:我仍然无法确定问题所在.这是我的xml:

<feed xmlns="http://www.w3.org/2005/Atom"  xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/"  xmlns:gf="http://schemas.google.com/finance/2007"  
      xmlns:gd="http://schemas.google.com/g/2005" >
  <id>http://finance.google.com/finance/feeds/xyx@google.com/portfolios</id>
  <updated>2009-12-15T19:32:21.000Z</updated>
  <category scheme="http://schemas.google.com/g/2005#kind"  term="http://schemas.google.com/finance/2007#portfolio" />
  <title type="text" >Portfolio Feed</title>
  <link rel="alternate"  type="text/html"  href="http://finance.google.com/finance/portfolio?action=view" />
  <link rel="http://schemas.google.com/g/2005#feed"  type="application/atom+xml"  href="http://finance.google.com/finance/feeds/default/portfolios" />
  <link rel="http://schemas.google.com/g/2005#post"  type="application/atom+xml"  href="http://finance.google.com/finance/feeds/default/portfolios" />
  <link rel="self"  type="application/atom+xml"  href="http://finance.google.com/finance/feeds/default/portfolios" />
  <openSearch:totalResults>24</openSearch:totalResults>
  <openSearch:startIndex>1</openSearch:startIndex>
  <openSearch:itemsPerPage>24</openSearch:itemsPerPage>
  <entry>
    <id>http://finance.google.com/finance/feeds/xyx@google.com/portfolios/2</id>
    <updated>2009-12-14T16:26:53.000Z</updated>
    <category scheme="http://schemas.google.com/g/2005#kind"  term="http://schemas.google.com/finance/2007#portfolio" />
    <title type="text" >Main</title>
    <link rel="self"  type="application/atom+xml"  href="http://finance.google.com/finance/feeds/default/portfolios/2" />
    <link rel="edit"  type="application/atom+xml"  href="http://finance.google.com/finance/feeds/default/portfolios/2" />
    <gd:feedLink href="http://finance.google.com/finance/feeds/xyx@google.com/portfolios/2/positions" />
    <gf:portfolioData currencyCode="USD"  gainPercentage="0.0"  return1w="0.0"  return1y="0.0"  return3m="0.0"  return3y="0.0"  return4w="0.0"  return5y="0.0"  returnOverall="0.0"  returnYTD="0.0" …
Run Code Online (Sandbox Code Playgroud)

.net xml xpath xmldocument

5
推荐指数
2
解决办法
4579
查看次数

标签 统计

.net ×2

xml ×2

xpath ×2

atom-feed ×1

c# ×1

namespaces ×1

rss ×1

xml-namespaces ×1

xmldocument ×1