>例如,这是托管在url http://localhost/test1上的
<?xml version="1.0" encoding="utf-8"?>
<MSG>
<arabic>
<translationOne>اول</translationOne>
<translationTwo>دوم</translationTwo>
</arabic>
<persian>
<translationOne>یک</translationOne>
<translationTwo>دوم</translationTwo>
</persian>
</MSG>c#类
var m_strFilePath = "http://localhost/test1";
string xmlStr;
using (var wc = new WebClient())
{
xmlStr = wc.DownloadString(m_strFilePath);
}
var xmldoc = new XmlDocument();
xmldoc.LoadXml(xmlStr);
XmlNodeList unNodeA = xmldoc.SelectNodes("MSG/arabic");
XmlNodeList unNodeP = xmldoc.SelectNodes("MSG/persian");
string arabic = "";
foreach (XmlNode i in unNodeA)
{
arabic += i["translationOne"].InnerText;
}
string persian= "";
string persian2 ="";
foreach (XmlNode ii in unNodeP)
{
persian+= ii["translationOne"].InnerText;
persian2+= ii["translationTwo"].InnerText;
}
->>print(arabic and persian);在这里,测试包含了不正确的格式,比如(اولدوم)-这是某种类型的测试(“P/P,P,P,P<†>P。
发布于 2021-02-17 15:39:05
最好使用LINQ。自2007年以来,它在.Net框架中可供使用。
c#
void Main()
{
XDocument xdoc = XDocument.Parse(@"<?xml version='1.0' encoding='utf-8'?><MSG>
<arabic>
<translationOne>اول</translationOne>
<translationTwo>دوم</translationTwo>
</arabic>
<persian>
<translationOne>یک</translationOne>
<translationTwo>دوم</translationTwo>
</persian>
</MSG>");
foreach (XElement elem in xdoc.Descendants("arabic").Elements())
{
Console.WriteLine("translation: {0}", elem.Value);
}
}如果需要从URL加载XML:
const string Url = @"http://hurt.super-toys.pl/xml/super_toys_ceneo_pelny.xml";
XDocument xdoc = XDocument.Load(Url);输出
translation: اول
translation: دومhttps://stackoverflow.com/questions/66245054
复制相似问题