非空格...运行时错误 [英] non-whitespace...runtime error
问题描述
尝试 { XDocument NameGram = new XDocument ( " grammar" , XDocument NameGram = new XDocument("grammar",
new XAttribute ( " mode" , " voice" ), new XAttribute("mode", "voice"),
new XAttribute ( " root" , " TOPLEVEL" ), new XAttribute("root","TOPLEVEL"),
new XElement ( " rule" , new new XElement("rule",new XAttribute("id","TOPLEVEL"),
new XAttribute ( " scope" , " public" ), new XAttribute("scope","public"),
new XElement ( " item" , new XElement("item",
new XComment 跨度> ( " FIRST NAME RETURN" ), new XComment("FIRST NAME RETURN"),
new XElement ( " item" , new XAttribute ( " repeat" , " 0-1" ), new XElement("item", new XAttribute("repeat","0-1"),
new XElement ( " ruleref" , new XAttribute ( " uri" , " #FIRSTNAME" )), 有没有人知道这个结构有什么问题? new XElement("ruleref",new XAttribute("uri","#FIRSTNAME")),
Does anyone know what is wrong with this construct? 这篇关于非空格...运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
推荐答案
简体:XDocument doc = new XDocument(" grammar");
您无法将文本节点添加为XDocument的子节点。 XML文档不允许根级文本节点(根据规范)。
您可能希望将其包装在根元素内。
谢谢,Hi,
Simplified: XDocument doc = new XDocument("grammar");
You can't add a text node as a child of the XDocument. XML document doesn't allow root level text nodes (as per the spec).
You probably want to wrap it inside a root element.
Thanks,