質問

I have an ASP .Net site where i am attempting to create a page to allow the user to create an XML document. 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.

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. Reading further i have seen some C# examples but they dont seem to be "readable" in 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? 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.

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帰属
所属していません StackOverflow
scroll top