节点类型Text不支持ReadElementContentAsString方法

时间:2016-04-13 20:40:38

标签: c# sql .net xml

我尝试解析XML并使用XMLreader从中获取所有信息。由于某种原因,它会从标题中抛出错误。这是xml:

<?xml version="1.0" encoding="utf-8" ?>
<queries>
  <selectparent table="Associates">"SELECT * FROM @table"</selectparent>
  <selectchild table="VehicleContract">"SELECT * FROM @table"</selectchild>
  <addchild table="VehicleContract" read="contractId, regNr, assoc_id, percentage, vehicleType, trailerNr">"INSERT into @table (contractId, regNr, assoc_id, percentage, vehicleType, trailerNr) VALUES (@id, @reg, @assort, @perc, @type, @trailer)"</addchild>
  <updatechild table="VehicleContract" read="contractId, regNr, assoc_id, percentage, vehicleType, trailerNr">"UPDATE @table SET regNr=@reg, assoc_id=@assort, percentage=@perc, vehicleType=@type, trailerNr=@trailer WHERE contractId=@id"</updatechild>
  <removechild table="VehicleContract" read="id">"DELETE from @table WHERE contractId=@id"</removechild>
</queries>

我的方法:

public string selectParent, selectChildren, addChildren, updateChildren, removeChildren;
public string[] addParams, updateParams, removeParams;
XmlTextReader reader = new XmlTextReader(base.Path);
reader.WhitespaceHandling = WhitespaceHandling.None;
reader.Read();
reader.Read(); 
reader.Read();
selectParent = reader.ReadElementContentAsString();
reader.Read();
selectChildren = reader.ReadElementContentAsString();
addParams = reader.GetAttribute("read").Split(',');
addChildren = reader.ReadElementContentAsString();
updateParams = reader.GetAttribute("read").Split(',');
updateChildren = reader.ReadElementContentAsString();
removeParams = reader.GetAttribute("read").Split(',');
removeChildren = reader.ReadElementContentAsString();

我在这一行得到错误:  selectParent = reader.ReadElementContentAsString 问题是什么?我一直在添加reader.Read()因为我在不同的节点类型上遇到了同样的错误。

据我所知,table属性应该从查询中替换@table ...但是有些东西是不对的。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我会使用xml linq

EXECUTE_FAILED