简体   繁体   English

使用Linq to XML创建XML文档

[英]Create XML doc with Linq to XML

I have an ASP .Net site where i am attempting to create a page to allow the user to create an XML document. 我有一个ASP .Net网站,我试图在其中创建一个页面以允许用户创建XML文档。 New with XML so I'm not sure if im missing something here but all i am trying to do is create an XML document using Linq to XML. XML的新功能,所以我不确定是否在这里遗漏了什么,但是我想做的就是使用Linq to XML创建XML文档。

I saw this example as part of my research 我将这个例子视为研究的一部分

Dim xmlDoc As XDocument = _
<?xml version="1.0" encoding="utf-16"?>
<!-- This is comment by you -->
<Employees>
<Employee id="EMP001">
<name>Wriju</name>
<![CDATA[ ~~~~~~~...~~~~~~~~]]>
</Employee>
</Employees>


xmlDoc.Save("somepath\somefile.xml")

but i just dont seem to be able to get it working in VS 2010 or VS 2013. As soon as i enter <?xml and enter to the next line i just get errors that the syntax is incorrect. 但是我似乎无法在VS 2010或VS 2013中使用它。一旦我输入<?xml并输入到下一行,我就会收到语法不正确的错误。 Reading further i have seen some C# examples but they dont seem to be "readable" in VB .Net. 进一步阅读,我已经看到了一些C#示例,但是在VB .Net中它们似乎并不“可读”。

I've tried using online converters but again no luck in that either. 我已经尝试过使用在线转换器,但同样也没有运气。 Could anyone guide me or point me to the right direction to create an XML document with elements etc using Linq to XML? 谁能指导我或为我指明正确的方向,以使用Linq to XML创建包含元素等的XML文档? I think i can use XDocument but i'm a little confused if that would allow me to use Linq to XML or if this is an old concept. 我认为我可以使用XDocument,但是如果让我使用Linq to XML或这是一个旧概念,我会有些困惑。

Thanks 谢谢

Use this 用这个

    Dim xmlDoc As XDocument = <?xml version="1.0" encoding="utf-16"?>
                              <!-- This is comment by you -->
                              <Employees>
                                  <Employee id="EMP001">
                                      <name>Wriju</name>
                                      <![CDATA[ ~~~~~~~...~~~~~~~~]]>
                                  </Employee>
                              </Employees>



    'it assume that /youfolder is in the root and it has read and write permission
    xmlDoc.Save(Server.MapPath("/yourfolder/somefile.xml"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM