0
我有像下面的程序。這個概念是從URL讀取XML值,但我的程序只讀取xml結構,而不是代碼數據。只有<Billing Address></Billing Address>...
等。但原始的XML值是<Billing Address>Strre1</Billing Address>
。本程序不讀取內部值。如何使用C#從URL讀取XML節點?
public static void zohoCRMReadAccounts()
{
var val = auth();
var val1= val[0];
var val2= val[1];
String xmlURL = "URL";
XmlTextReader xmlReader = new XmlTextReader(xmlURL);
while (xmlReader.Read())
{
switch (xmlReader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
Console.Write("<" + xmlReader.Name);
// Read the attributes:
while (xmlReader.MoveToNextAttribute())
Console.Write(" " + xmlReader.Name + "=’"
+ xmlReader.Value + "’");
Console.WriteLine(">");
break;
case XmlNodeType.Text: //Display the text in each element.
Console.WriteLine(xmlReader.Value);
break;
case XmlNodeType.EndElement: //Display the end of the element.
Console.Write("</" + xmlReader.Name);
Console.WriteLine(">");
break;
}
}
Console.WriteLine("Press any key to continue…");
Console.ReadLine(); //Pause
}
請幫我解決
是否有一個特定的原因,你爲什麼使用複雜的'XmlTextReader'而不是簡單得多的'XmlDocument'或'XDocument'類? –
@DanielHilgarth如果你知道任何最簡單的想法,那麼請在這裏分享 – 1630082