我想解析这个 XML:
<?xml version="1.0" encoding="utf-8" ?>
<feed xml:base="http://staging.bradinsight.win.web.emap-intl.net/ALFAPI/AlfWebApi/"
xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<id>http://staging.bradinsight.win.web.emap-intl.net/alfapi/alfwebapi/AuthenticationToken</id>
<title
type="text">AuthenticationToken</title>
<updated>2013-01-22T13:07:10Z</updated>
<link rel="self" title="AuthenticationToken"
href="AuthenticationToken" />
<entry>
<id>http://staging.bradinsight.win.web.emap-intl.net/ALFAPI/AlfWebApi/AuthenticationToken(1)</id>
<category
term="AlfWebApiInfrastructure.Poco.AuthenticationToken" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
/>
<link rel="edit" title="AuthenticationToken" href="AuthenticationToken(1)"
/>
<title />
<updated>2013-01-22T13:07:10Z</updated>
<author>
<name />
</author>
<content type="application/xml">
<m:properties>
<d:AuthenticationTokenId m:type="Edm.Int32">1</d:AuthenticationTokenId>
<d:IsValid m:type="Edm.Boolean">true</d:IsValid>
<d:Message>Success</d:Message>
<d:Token>B50F114BF0BE2B7B210132B1D188DAD8AD6719D808BD59D800509A951C4FB7445687E4F75FCE22C52219495D5172AFFB0FB20FE4E949D20CA0F5055D7F9237C6B5EA4028692A63A2AB0E1703C4668EE2D4C58473A58F1B25AC8ADE4DE12B2A7581064217C5040EDB3A4E302DA1714F21BBEA7D82748B4DF9524C5FED6ED7E265
<
/d:Token>
</m:properties>
</content>
</entry>
使用此代码:
WebRequest wrGETURL;
wrGETURL = WebRequest.Create(sURL);
StringBuilder output = new StringBuilder();
Stream objStream;
try
{
objStream = wrGETURL.GetResponse().GetResponseStream();
StreamReader objReader = new StreamReader(objStream);
// Create an XmlReader
using (XmlReader reader = XmlReader.Create(new StringReader(objReader.ReadToEnd())))
{
XmlWriterSettings ws = new XmlWriterSettings();
ws.Indent = true;
using (XmlWriter writer = XmlWriter.Create(output, ws))
{
// Parse the file and display each of the nodes.
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
writer.WriteStartElement(reader.Name);
break;
case XmlNodeType.Text:
writer.WriteString(reader.Value);
break;
case XmlNodeType.XmlDeclaration:
case XmlNodeType.ProcessingInstruction:
writer.WriteProcessingInstruction(reader.Name, reader.Value);
break;
case XmlNodeType.Comment:
writer.WriteComment(reader.Value);
break;
case XmlNodeType.EndElement:
writer.WriteFullEndElement();
break;
}
}
}
}
但是我的 C# 代码无法解析 tag 。
我收到此错误:
{System.ArgumentException: Invalid name character in 'm:properties'. The ':' character, hexadecimal value 0x3A, cannot be included in a name.
at System.Xml.XmlWellFormedWriter.CheckNCName(String ncname)
at System.Xml.XmlWellFormedWriter.WriteStartElement(String prefix, String localName, String ns)
at System.Xml.XmlWriter.WriteStartElement(String localName)
at AlfApi.Controllers.HomeController.Index() in c:\users\nickgowdy\documents\visual studio 2010\Projects\AlfApi\AlfApi\Controllers\HomeController.cs:line 51}
有谁知道如何解析这个xml?
谢谢!