xml-怎么了-我听不懂 [英] Xml - What's wrong - I cant understand

查看:112
本文介绍了xml-怎么了-我听不懂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我无法解决.

当我尝试将项目添加到XML文件时,程序可以正常运行,并且不会中断.


我用来创建XML文件的子目录:

Hi, I have a question, which i can''t solve.

When I try to add a item to my XML file, the program do all right, and don''t break.


The sub I use to creat my XML file:

Sub pastaxml()
    System.IO.Directory.CreateDirectory(pasta)
    Dim xmlw As New XmlTextWriter(bdFile, System.Text.Encoding.UTF8)
    xmlw.Formatting = Formatting.Indented
    xmlw.WriteStartDocument()
    xmlw.WriteStartElement("musicas")
    xmlw.WriteEndElement()
    xmlw.WriteEndDocument()
    xmlw.Flush()
    xmlw.Close()
End Sub



我用来尝试添加新项目的子项目:



The sub I use to try to add the new item:

Form1.numero = Form1.numero + 1
nome = TextBox1.Text
compositor = TextBox2.Text
prgutilizado = TextBox3.Text
ano = TextBox4.Text
arranjo = TextBox5.Text
tipo = ComboBox1.Text
ficheiro = TextBox7.Text
pdf = TextBox7.Text
Dim xDoc = XDocument.Load(Form1.bdFile)
Dim parent = xDoc.<musicas>.FirstOrDefault()
Dim element = <musicas id=<%= numero %> nome=<%= nome %> compositor=<%= compositor %>         programautilizado=<%= prgutilizado %> ano=<%= ano %> arranjo=<%= arranjo %> tipo=<%= arranjo %> ficheiro=<%= ficheiro %> pdf=<%= pdf %>/>
parent.Add(element)



有人可以向我解释我在做什么错.

请帮我解决这个问题,我厌倦了一次又一次的尝试.


PS:我的英语不是很完美,如果我在文本中有任何错误,请告诉我.



Can someone explain to me what I am doing wrong.

Please help me to solve this, I''m tired of trying and trying again.


PS: My english isnt'' perfect, if I have any errors in text please told me.

推荐答案

如果您发布的代码显示正确,则您试图直接在代码中构建XML.不支持.相反,您可以例如创建一个字符串并在该字符串内定义xml.例如
If the code you''ve posted is displayed correctly, you''re trying to build a XML directly in the code. That isn''t supported. Instead you can for example create a string and define the xml inside the string. For example
...
Dim element = "<musicas id=<%= numero %> nome=<%= nome %> compositor=<%= compositor %>         programautilizado=<%= prgutilizado %> ano=<%= ano %> arranjo=<%= arranjo %> tipo=<%= arranjo %> ficheiro=<%= ficheiro %> pdf=<%= pdf %>/>"
...


大声笑,我忘了一行.

Lol, I forget a line.

xDoc.Save(bdfile)



抱歉



sorry


这篇关于xml-怎么了-我听不懂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆