我用xmltextwriter写了一个xml文件,为什么找不到该文件
2007-03-08 20:53
465 查看
Private Shared filename As String = "sampledata.xml"
Public Shared Sub Main()
Dim writer As XmlTextWriter = Nothing
writer = New XmlTextWriter(filename, Nothing)
'Use indenting for readability.
writer.Formatting = Formatting.Indented
'Write the XML delcaration.
writer.WriteStartDocument()
'Write the ProcessingInstruction node.
Dim PItext As String = "type='text/xsl' href='book.xsl'"
writer.WriteProcessingInstruction("xml-stylesheet", PItext)
'Write the DocumentType node.
writer.WriteDocType("book", Nothing, Nothing, "<!ENTITY h 'hardcover'>")
'Write a Comment node.
writer.WriteComment("sample XML")
'Write a root element.
writer.WriteStartElement("book")
'Write the genre attribute.
writer.WriteAttributeString("genre", "novel")
'Write the ISBN attribute.
writer.WriteAttributeString("ISBN", "1-8630-014")
'Write the title.
writer.WriteElementString("title", "The Handmaid's Tale")
'Write the style element.
writer.WriteStartElement("style")
writer.WriteEntityRef("h")
writer.WriteEndElement()
'Write the price.
writer.WriteElementString("price", "19.95")
'Write CDATA.
writer.WriteCData("Prices 15% off!!")
'Write the close tag for the root element.
writer.WriteEndElement()
writer.WriteEndDocument()
'Write the XML to file and close the writer.
writer.Flush()
writer.Close()
'Load the file into an XmlDocument to ensure well formed XML.
Dim doc As New XmlDocument()
'Preserve white space for readability.
doc.PreserveWhitespace = True
'Load the file.
doc.Load(filename)
'Display the XML content to the console.
Console.Write(doc.InnerXml)
End Sub 'Main
Public Shared Sub Main()
Dim writer As XmlTextWriter = Nothing
writer = New XmlTextWriter(filename, Nothing)
'Use indenting for readability.
writer.Formatting = Formatting.Indented
'Write the XML delcaration.
writer.WriteStartDocument()
'Write the ProcessingInstruction node.
Dim PItext As String = "type='text/xsl' href='book.xsl'"
writer.WriteProcessingInstruction("xml-stylesheet", PItext)
'Write the DocumentType node.
writer.WriteDocType("book", Nothing, Nothing, "<!ENTITY h 'hardcover'>")
'Write a Comment node.
writer.WriteComment("sample XML")
'Write a root element.
writer.WriteStartElement("book")
'Write the genre attribute.
writer.WriteAttributeString("genre", "novel")
'Write the ISBN attribute.
writer.WriteAttributeString("ISBN", "1-8630-014")
'Write the title.
writer.WriteElementString("title", "The Handmaid's Tale")
'Write the style element.
writer.WriteStartElement("style")
writer.WriteEntityRef("h")
writer.WriteEndElement()
'Write the price.
writer.WriteElementString("price", "19.95")
'Write CDATA.
writer.WriteCData("Prices 15% off!!")
'Write the close tag for the root element.
writer.WriteEndElement()
writer.WriteEndDocument()
'Write the XML to file and close the writer.
writer.Flush()
writer.Close()
'Load the file into an XmlDocument to ensure well formed XML.
Dim doc As New XmlDocument()
'Preserve white space for readability.
doc.PreserveWhitespace = True
'Load the file.
doc.Load(filename)
'Display the XML content to the console.
Console.Write(doc.InnerXml)
End Sub 'Main
相关文章推荐
- Android中其中一个Activity可以对另一个Activity的xml文件中的EditText设置进行设置吗?
- 使用XmlTextWriter生成XML文件
- C#中XmlTextWriter读写xml文件详细介绍
- 利用xmltextreader和xmltextwriter读写xml文件
- 使用XmlTextWriter生成XML文件
- asp.net实现在XmlTextWriter中写入一个CDATA的方法
- asp.net实现在XmlTextWriter中写入一个CDATA的方法
- 用XmlTextWriter写出的XML文件没有换行,用记事本打开XML文件的时候都写在了一行上,请问怎样加入换行!
- C#中XmlTextWriter读写xml文件详细介绍(转)
- 使用XmlTextWriter与XmlTextReader访问创建和读取XML文件
- 在XmlTextWriter中写入一个cdata
- 用.net生成Google的SiteMaps的XML规范文件。(利用XmlTextWriter对象)
- 今天试了一下ajax dropdownlist联动,实际上是先写在一个XmlTextWriter(Response.OutputStream,然后再response回去(等同于一个XML),里面有很多要注意的地方,比如dropdownlist的清空,遍历X
- 今天试了一下ajax dropdownlist联动,实际上是先写在一个XmlTextWriter(Response.OutputStream,然后再response回去(等同于一个XML),里面有很多要注意的地方,比如dropdownlist的清空,遍历X
- C#中XmlTextWriter读写xml文件详细介绍
- Eclipse布局文件添加两个TextView,为什么运行后置显示一个
- XML文件中画一条横线或竖线,给一个textview画下划线
- C# XmlTextWriter和XmlTextReader 读写XML文件
- ASP.NET WebApi 上传文件时异常 Failed to execute send on XMLHttpRequest 的一个处理方法
- xml学习(二)---运用XmlTextWriter及XmlTextReader操作Xml