如何使用节点前缀创建xml文档,如:
<sphinx:docset>
<sphinx:schema>
<sphinx:field name="subject"/>
<sphinx:field name="content"/>
<sphinx:attr name="published" type="timestamp"/>
</sphinx:schema>
Run Code Online (Sandbox Code Playgroud)
当我尝试运行像new XElement("sphinx:docset")
我得到异常的东西时
未处理的异常:System.Xml.XmlException:':'字符,十六进制值0x3A,不能包含在名称中.
在System.Xml.XmlConvert.VerifyNCName(String name,ExceptionType exceptionTyp e)
处System.Xml.Linq.XName..ctor(XNamespace ns,String localName)
处于System.Xml.Linq.XNamespace.GetName(String localName)
at System .Xml.Linq.XName.Get(String expandedName)
我有这个代码:
/*string theXml =
@"<Response xmlns=""http://myvalue.com""><Result xmlns:a=""http://schemas.datacontract.org/2004/07/My.Namespace"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><a:TheBool>true</a:TheBool><a:TheId>1</a:TheId></Result></Response>";*/
string theXml = @"<Response><Result><TheBool>true</TheBool><TheId>1</TheId></Result></Response>";
XDocument xmlElements = XDocument.Parse(theXml);
var elements = from data in xmlElements.Descendants("Result")
select new {
TheBool = (bool)data.Element("TheBool"),
TheId = (int)data.Element("TheId"),
};
foreach (var element in elements)
{
Console.WriteLine(element.TheBool);
Console.WriteLine(element.TheId);
}
Run Code Online (Sandbox Code Playgroud)
当我使用第一个值为xml时,结果为null,而对于第二个值,我有很好的值...
如何使用xmlns值将Linq用于Xml?