problem with my code

< xml version="1.0" encoding="UTF-8" >

<Slides>

<slideNode jpgURL="pic/normal/galeria_0/0.jpg" />

</Slides> 

But I want this

< xml version="1.0" encoding="UTF-8" >

<Slides>

<slideNode jpgURL="pic/normal/galeria_0/0.jpg"> </slideNode >

</Slides>

HOW I CAN FORMAT MY XML THIS WAY

THIS THE CODE THAT GENERATE MY XML

XmlDocument doc = new XmlDocument();

//Load in the users xml file

try

{

doc.Load(@"C:\works\WEBS\colegiosj\slideapp\xmlfile\galerypics.xml");

}

catch(Exception err)

{

//Oh dear the document probably wasn't well written

//Response.Write("error: " + err.Message);

}

//XmlNode=doc.CreateNode(XmlNodeType.XmlDeclaration,"","");

XmlNode newNode = doc.CreateElement("slideNode");

//Create a new attribute assign the value and append it to the new node.

//Repeat this until all attributes have been added

XmlAttribute newAttribute = doc.CreateAttribute("jpgURL");

newAttribute.Value = "pic/normal/galeria_0/0.jpg";

newNode.Attributes.Append(newAttribute);

//Append the new node to the document

doc.DocumentElement.AppendChild(newNode);

//Save the document

doc.Save(@"C:\works\WEBS\colegiosj\slideapp\xmlfile\galerypics.xml");

}



Answer this question

problem with my code

  • Antony Perkov

    It will be like that as there is no data in that tag.

    If there is no data it will be like this:

    <something />

    With data it will be like this:

    <something>I have data now</something>

    Martin



  • Marko Simic

    oo I see your point. Hey may be you can help me with other problem I got . as you see Im a new by xml and C# this is my first proyect and I need a little help with this.

    This is my xml I just want to update jpeg_o and other attributes to a new value

    <galerias galeria_id="1" nombre="sdsds" Detalles="sdfsdfsf" jpeg_0="" jpeg_1="" jpeg_2="" jpeg_3="" jpeg_4="" jpeg_5="" jpeg_6="" jpeg_7="" jpeg_8="" jpeg_9="" jpeg_10="" jpeg_11="">

    </galerias>

    I dont have any Idea how to perform this Can you help me with this
    I just want to change jpeg_0 and other to a new value


  • Kunal105

    If there is no data between the tags what is the point in having:

    <tag></tag>

    It might as well be:

    <tag />

    They are both the same.

    Martin



  • Reza

    Sow what you mean or try to said is ther is no innerText = "";
  • problem with my code