Click here to Skip to main content
15,896,606 members
Home / Discussions / C#
   

C#

 
GeneralRe: modifying xml field data's using c# Pin
dhol6-Jan-05 16:38
dhol6-Jan-05 16:38 
GeneralRe: modifying xml field data's using c# Pin
perlmunger7-Jan-05 6:27
perlmunger7-Jan-05 6:27 
GeneralRe: modifying xml field data's using c# Pin
dhol7-Jan-05 17:05
dhol7-Jan-05 17:05 
GeneralMethod return Value Pin
webhay5-Jan-05 23:43
webhay5-Jan-05 23:43 
GeneralRe: Method return Value Pin
Stefan Troschuetz5-Jan-05 23:59
Stefan Troschuetz5-Jan-05 23:59 
GeneralRe: Method return Value Pin
haimlz6-Jan-05 1:02
haimlz6-Jan-05 1:02 
GeneralRe: Method return Value Pin
Salil Khedkar6-Jan-05 1:07
Salil Khedkar6-Jan-05 1:07 
GeneralXmlDocument Write problems and Add Identation Help! Pin
Chua Wen Ching5-Jan-05 23:40
Chua Wen Ching5-Jan-05 23:40 
Hi there,

I have 2 questions to ask.

1) I have this code...

XmlDocument doc = new XmlDocument();
doc.Load(myXmlPath);

int maxValue = 0;
int newValue = 0;

XmlNodeList nodeList = doc.SelectNodes("//Product");

foreach (XmlNode node in nodeList)
maxValue = XmlConvert.ToInt32(node.Attributes["id"].Value);

XmlElement newElem = doc.CreateElement("Product");
newValue = maxValue + 1;
XmlAttribute newAttr = doc.CreateAttribute("id");
newAttr.Value = newValue.ToString();
newElem.Attributes.Append(newAttr);

doc.DocumentElement.AppendChild(newElem);
XmlElement elem = doc.CreateElement("Description");
elem.InnerText = "JVC Camera";
doc.DocumentElement.AppendChild(elem);

XmlTextWriter wrtr = new XmlTextWriter(myXmlPath, Encoding.UTF8);
doc.WriteTo(wrtr);
wrtr.Close();

Xml (Before) // xml has identation nicely
----------------
<?xml version="1.0" encoding="utf-8"?>
<ProductList>
<Product id="1">
<Description>Panasonic Camcorder</Description>
</Product>
</ProductList>

Xml(After) // xml has no identation
--------------
<?xml version="1.0" encoding="utf-8"?>
<ProductList>
<Product id="1">
<Description>Panasonic Camcorder</Description>
</Product>
<Product id="2" />
<Description>JVC Camera</Description>
</ProductList>

Xml (Expected this)
-----------------------
<?xml version="1.0" encoding="utf-8"?>
<ProductList>
<Product id="1">
<Description>Panosonic Camcorder</Description>
</Product>
<Product id="2">
<Description>JVC Camera</Description>
</Product>
</ProductList>

Note: I want the Second Description tag to be part of Product id="2", but with my C# codes, i can't achieve it.

2)

After i perform the C# code on top, my codes has no more identation. It seems that it removes all the whitespaces to this. (Please take note, the above xml examples, i manually re-arrange the generated xml for clear view).

Xml (After)
--------------
<?xml version="1.0" encoding="utf-8"?><ProductList><Product id="1"><Description>Panasonic Camcorder</Description></Product><Product id="2" /><Description>JVC Camera</Description></ProductList>

I hope i can indent nicely, just like what i did above on original xml file.

Any help please?
--
Regards,
Chua Wen Ching
Visit us at http://www.necoders.com

Regards,
Chua Wen Ching
Visit us at http://www.necoders.com
GeneralRe: XmlDocument Write problems and Add Identation Help! Pin
Stanimir_Stoyanov6-Jan-05 0:07
Stanimir_Stoyanov6-Jan-05 0:07 
GeneralRe: XmlDocument Write problems and Add Identation Help! Pin
J4amieC6-Jan-05 3:03
J4amieC6-Jan-05 3:03 
GeneralRe: XmlDocument Write problems and Add Identation Help! Pin
Chua Wen Ching6-Jan-05 13:34
Chua Wen Ching6-Jan-05 13:34 
GeneralList View items - exporting and importing data Pin
Stanimir_Stoyanov5-Jan-05 22:43
Stanimir_Stoyanov5-Jan-05 22:43 
GeneralRe: List View items - exporting and importing data Pin
Patric_J6-Jan-05 10:55
Patric_J6-Jan-05 10:55 
GeneralPrint without preview in C# Pin
gbess5-Jan-05 22:39
gbess5-Jan-05 22:39 
Generalimage screensaver with mem probs Pin
Steven_T5-Jan-05 20:41
Steven_T5-Jan-05 20:41 
GeneralRe: image screensaver with mem probs Pin
perlmunger6-Jan-05 6:11
perlmunger6-Jan-05 6:11 
GeneralRe: image screensaver with mem probs Pin
Steven_T6-Jan-05 21:21
Steven_T6-Jan-05 21:21 
GeneralRe: image screensaver with mem probs Pin
Steven_T6-Jan-05 23:23
Steven_T6-Jan-05 23:23 
QuestionHow to get explorer like (custom?) controls. Pin
E_NoName5-Jan-05 16:30
E_NoName5-Jan-05 16:30 
AnswerRe: How to get explorer like (custom?) controls. Pin
Alex Korchemniy5-Jan-05 19:18
Alex Korchemniy5-Jan-05 19:18 
GeneralProblem having Rational XDE Pin
amalatsliit5-Jan-05 15:00
amalatsliit5-Jan-05 15:00 
GeneralRe: Problem having Rational XDE Pin
Nick Parker6-Jan-05 7:06
protectorNick Parker6-Jan-05 7:06 
GeneralRe: Problem having Rational XDE Pin
amalatsliit6-Jan-05 15:01
amalatsliit6-Jan-05 15:01 
GeneralApplication.Exit Pin
Nbip5-Jan-05 14:30
Nbip5-Jan-05 14:30 
GeneralRe: Application.Exit Pin
Stefan Troschuetz5-Jan-05 20:57
Stefan Troschuetz5-Jan-05 20:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.