Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
<?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>


Now suppose i want to add extra image under "album" part so how i add extra image code in XML through programming.
Posted
Updated 28-Jun-11 21:18pm
v2

Hi,

You can use the following code to insert the slide element to add extra images to the album;

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


Hope this helps... :)

Jasmin
 
Share this answer
 
Comments
Tarun.K.S 29-Jun-11 3:46am    
This will work my 5, do have a look at my answer, I have used Linq to XML.
Have a look at this[^] - it may help you.
 
Share this answer
 
Apart from Jasmin's answer, here is another way using Linq to XML. Advantage is shorter code as you will see.

C#
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900