一个XML转换的例子

问:
我想把字符串转换成stream,
然后
System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader(System.IO.Stream input)

______________________________________________________________________________________________
答1:
为何一定要转呢?

string xmlFrag ="<book> " +
                         "<title>Pride And Prejudice</title>" +
                         "<bk:genre>novel</bk:genre>" +
                         "</book>";

    //Create the XmlNamespaceManager.
    NameTable nt = new NameTable();
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
    nsmgr.AddNamespace("bk", "urn:sample");

    //Create the XmlParserContext.
    XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);

    //Create the reader.
    XmlTextReader reader = new XmlTextReader(xmlFrag, XmlNodeType.Element, context);

你可能感兴趣的:(xml)