Writing XML Element 'id="" ' tag with C#

GeX

GeX

Soldato
Joined
17 Dec 2002
Posts
6,850
Location
Manchester
i'm having the same trouble with C#/asp.net

I am trying to write this;

Code:
    <Style id="yellowLineGreenPoly">
      <LineStyle>
        <color>7f00ffff</color>
        <width>4</width>
      </LineStyle>
      <PolyStyle>
        <color>7f00ff00</color>
      </PolyStyle>
    </Style>

and having issues with the 'ID' bit (won't parse as is, and won't work properly if modified);

Code:
xmlWriter.WriteStartElement("Style id="yellowLineGreenPoly"");

bit of pondering and;

ok, fixed my problem;

Code:
xmlWriter.WriteStartElement("Style id=\"yellowLineGreenPoly\"");

BUT

GeX: that's not correct. You should take it to your own thread anyway as it is completely off topic to this thread.

it works and i'm confused as to why it's wrong :confused:
 
Caporegime
Joined
18 Oct 2002
Posts
29,490
Location
Back in East London
It's creating a tag called Style id="yellowLineGreenPoly". Note it is not creating a tag called Style with an attribute called id.

Use this instead:
Code:
writer.WriteStartElement("Style");
writer.WriteStartAttribute("id");
writer.WriteValue("yellowLineGreenPoly");
writer.WriteEndElement();
 
Back
Top Bottom