日期:2014-05-18 浏览次数:20470 次
string strXml = @"<Table> <Row > <Title>首页</Title> <Name>企业首页</Name> <Href>_self</Href> <Url>index.html</Url> <Mark>index</Mark> </Row> <Row > <Title>产品展示</Title> <Name>产品展示</Name> <Href>_self</Href> <Url>Pro.html</Url> <Mark>Pro</Mark> </Row> </Table>"; XmlDocument xdoc = new XmlDocument(); xdoc.LoadXml(strXml); string strXPath = "/Table/Row[Mark='index']"; XmlNodeList oXmlNodes = xdoc.SelectNodes(strXPath); //*************已经成取到所需的信息了*********** xdoc = new XmlDocument(); XmlDeclaration xmlDec = xdoc.CreateXmlDeclaration("1.0", "utf-8", null); XmlElement rootNode = xdoc.CreateElement("Table"); xdoc.InsertBefore(xmlDec, xdoc.DocumentElement); xdoc.AppendChild(rootNode); foreach (XmlNode node in oXmlNodes) { XmlElement xmlNew = xdoc.CreateElement("Row"); xmlNew.InnerXml = node.InnerXml; rootNode.AppendChild(xmlNew); } DataSet ds = new DataSet(); StringReader stream = new StringReader(xdoc.InnerXml); XmlTextReader reader = new XmlTextReader(stream); ds.ReadXml(reader);