[英]xml reader and namespaces in c#
我正在嘗試使用xml reader讀取xml數據,該xml文件包含很多前綴,因此我在XmlNamespaceManager
包含了名稱空間,示例代碼
using (XmlReader reader = new XmlTextReader(fileName))
{
XmlNamespaceManager nsmanager = new XmlNamespaceManager(reader.NameTable);
nsmanager.AddNamespace("s", "http://www.google.com/shopping/api/schemas/2010");
while (reader.Read())
{
switch (reader.Name)
{
case "s:name":
Console.WriteLine(reader.Name);
break;
case "s:condition":
Console.WriteLine(reader.Name);
break;
}
}
}
其輸出的空行,這是包含名稱空間的正確方法嗎?
在vb.net中,我將命名空間導入為
Imports <xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Imports <xmlns:msxsl="urn:schemas-microsoft-com:xslt">
Imports <xmlns:rh="ReportHub">
Imports <xmlns="http://www.w3.org/2005/Atom">
Imports <xmlns:gd="http://schemas.google.com/g/2005">
Imports <xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">
Imports <xmlns:s="http://www.google.com/shopping/api/schemas/2010">
通過使用reader.ReadElementString
而不是reader.Value
解決的問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.