一个字符串strXML,里边是一个XML文档容,现在我要将里边的各元素解析出来,请问该用那个对象可以输入字符串,我用过XMLTextReader,但是里边只是接收XML文档所在的文件路径的字符串的和System.IO.TextReader类型的数据,请问用那个对象可以接收XML字符串.
如:strXML="<?xml version="1.0" encoding="gb2312"><message><good>1213</good></message>"现在我想将这个串传给一个XML对像,但传的不是XML文件,然后通过这可对象可以解析出<good>元素和值1213。请问如何实现
如:strXML="<?xml version="1.0" encoding="gb2312"><message><good>1213</good></message>"现在我想将这个串传给一个XML对像,但传的不是XML文件,然后通过这可对象可以解析出<good>元素和值1213。请问如何实现
strXML=@"<?xml version="1.0" encoding="gb2312"><message><good>1213</good></message>"
System.IO.StringReader strReader=new System.IO.StringReader(strXML);System.Xml.XmlTextReader xmlreader=new System.Xml.XmlTextReader(strReader);
while(xmlreader.Read())
{
MessageBox.Show(xmlreader.Name+ " "+xmlreader.Value);
}
你应该做的是添加结点,属性和内容。
反正用XmlDocument可以做一切。
// Create a "ProjectName" node
XmlElement projectNameElement = xmlDocument.CreateElement("ProjectName", "x-schema:FDTTaCProjectSchema.xml");
// Create an attribute of this node
XmlAttribute attrProjectName = xmlDocument.CreateAttribute("name");
attrProjectName.Value = projectName;
// Add the attribute to the node
projectNameElement.SetAttributeNode(attrProjectName);
// Append it to the "Project" node
projectElement.AppendChild(projectNameElement);