这是一个非常新手的问题,因为我很少使用XML。我正在尝试为Subsonic API编写一些东西。xml如下所示
<?xml version="1.0" encoding="UTF-8"?>
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.6.0">
<indexes lastModified="1313158157783">
<index name="A">
<artist name="Albums" id="5c5c3139322e3136382e322e31305c566f6c756d655f315c4d757369635c416c62756d73"/>
</index>
<index name="S">
<artist name="Singles" id="5c5c3139322e3136382e322e31305c566f6c756d655f315c4d757369635c53696e676c6573"/>
</index>
</indexes>
</subsonic-response>我只是在尝试获取索引节点。
我正在尝试这样做,但不确定我这样做是否正确。SelectNodes和SelectSingleNode都返回emtpy。我确信我错过了一些简单的东西。
XmlNamespaceManager nsmgr = new XmlNamespaceManager(index.NameTable);
nsmgr.AddNamespace("", "http://subsonic.org/restapi");
XmlNodeList xnList = index.SelectNodes("/subsonic-response/indexes/index", nsmgr);
XmlNode mainnode = index.SelectSingleNode("/subsonic-response", nsmgr);
foreach (XmlNode xn in xnList)
{
}我尝试过使用和不使用名称空间管理器,这都是一样的
发布于 2011-08-13 03:57:01
尝试使用非空的XML命名空间前缀:
XmlNamespaceManager nsmgr = new XmlNamespaceManager(index.NameTable);
nsmgr.AddNamespace("x", "http://subsonic.org/restapi");
XmlNodeList xnList = index.SelectNodes("/x:subsonic-response/x:indexes/x:index", nsmgr);
XmlNode mainnode = index.SelectSingleNode("/x:subsonic-response", nsmgr);我在尝试使用空字符串作为(默认) XML名称空间前缀时遇到了问题
发布于 2011-08-13 03:56:18
这样如何:
nsmgr.AddNamespace("x", "http://subsonic.org/restapi");和:
XmlNodeList xnList = index.SelectNodes("/x:subsonic-response/x:indexes/x:index", nsmgr);https://stackoverflow.com/questions/7045594
复制相似问题