我在客户端想把字符串转换成xml,然后再传到service,我怎么把一个字符串转换成xml 呢?

解决方案 »

  1.   

    XmlDocument.LoadXml("xml的字符串")
      

  2.   

    using System;
    using System.IO;
    using System.Xml;public class Sample
    {
      public static void Main()
      {      XmlDocument doc = new XmlDocument();
    string xml=@"<?xml version='1.0' encoding='gb2312' ?>
    <words>
    <word c='中文' e='english' />
    </words>";
          doc.LoadXML(xml);      //Create an XmlNamespaceManager for resolving namespaces.
          XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
          nsmgr.AddNamespace("bk", "urn:samples");      //Select and display the value of all the ISBN attributes.
          XmlNodeList nodeList;
          XmlElement root = doc.DocumentElement;
          nodeList = root.SelectNodes("/bookstore/book/@bk:ISBN", nsmgr);
          foreach (XmlNode isbn in nodeList){
            Console.WriteLine(isbn.Value);
          }   }}