本文介绍了如何用XML编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
早上好,我有一个asp.net Web应用程序,我正在从某个外部soft.flash生成一个Fix images的Flash文档.随着那个XML文件的生成,请参见xml代码
Good Morning to all I have an asp.net web application I am generating a flash document of Fix images from some external soft.with that a XML file is generating plz see xml code
<?xml version="1.0" encoding="UTF-8" ?>
<flash_parameters>
<preferences>
<golbal>
<basic_property html_title="Title" loadStyle="Bar" hideAdobeMenu="false" photoDynamicShow="true" enableURL="true" startAutoPlay="true"/>
<music_property path="" stream="true" loop="true"/>
<description_property enable="true" backgroundColor="0xc0c0c0" backgroundAlpha="10" cssText="a:link{text-decoration: underline;} a:hover{color:#ff0000; text-decoration: none;} text-decoration: underline;} .body{color:#ff5500;font-size:20px;}" align="bottom"/>
<background_property backgroundColor="0x000000" backgroundImage="res/bg-0162.gif" mode="tile"/>
</golbal>
<thumbnail>
<basic_property thumWidth="100" thumHeight="80" thumbnailborderColor="0xfffbf0" currentbordercolor="0x000000" thumborder="5" thumSpacing="8"/>
<button_property enablebutton="true" buttoncolor="0xfffbf0"/>
</thumbnail>
</preferences>
<album>
<slide jpegURL="thumbs/t_0009.jpg" d_URL="slides/p_0009.jpg" transition="0" panzoom="1" URLTarget="0" phototime="2" url="" title="DSCF1810" width="800" height="600"/>
<slide jpegURL="thumbs/t_0010.jpg" d_URL="slides/p_0010.jpg" transition="0" panzoom="1" URLTarget="0" phototime="2" url="" title="DSCF1813" width="800" height="600"/>
</album>
</flash_parameters>
现在,假设我想在专辑"部分下添加额外的图像,以便我如何通过编程在XML中添加额外的图像代码.
Now suppose i want to add extra image under "album" part so how i add extra image code in XML through programming.
推荐答案
Private Sub InsertImage(ByVal jpegURL As String, _
ByVal dURL As String, _
ByVal title As String, _
ByVal width As Integer, _
ByVal height As Integer)
Dim doc As New XmlDocument
Dim filePath As String
filePath = "xml file path"
doc.Load(filePath)
Dim root As XmlNode = doc.DocumentElement
Dim nav As Xml.XPath.XPathNavigator = doc.CreateNavigator
nav = nav.SelectSingleNode("/flash_parameters/album") '' Select the album element
nav.AppendChildElement("", "slide", "", "") '' add the slide element into album
nav = nav.SelectSingleNode("/flash_parameters/album/slide[last()]") '' select the last inserted slide element
'' add attributes to the selected/last inserted slide element
nav.CreateAttribute("", "jpegURL", "", jpegURL)
nav.CreateAttribute("", "d_URL", "", dURL)
nav.CreateAttribute("", "transition", "", "0")
nav.CreateAttribute("", "panzoom", "", "1")
nav.CreateAttribute("", "URLTarget", "", "0")
nav.CreateAttribute("", "phototime", "", "2")
nav.CreateAttribute("", "url", "", "")
nav.CreateAttribute("", "title", "", title)
nav.CreateAttribute("", "width", "", width)
nav.CreateAttribute("", "height", "", height)
doc.Save(filePath) '' save the xml file
End Sub
希望这对您有帮助... :)
Jasmin
Hope this helps... :)
Jasmin
XDocument xDoc = XDocument.Load(filePath);
XElement albumElem = xDoc.XPathSelectElement("//slide[position()=last()]");
albumElem.AddAfterSelf(new XElement("slide",
new XAttribute("jpegURL", "some value"),
new XAttribute("d_URL", "some value"),
new XAttribute("transition", 0),
new XAttribute("panzoom", 2))); //Add more attributes as per your need.
xDoc.Save(filePath);
如您所见,代码简明易懂.希望对您有所帮助.
As you can see the code is concise and readable. Hope it helped.
这篇关于如何用XML编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!