1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'HTML, Graphics & Programming' started by GeX, 4 Mar 2010.

  1. GeX

    Soldato

    Joined: 17 Dec 2002

    Posts: 6,489

    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

    it works and i'm confused as to why it's wrong :confused:
     
  2. Dj_Jestar

    Caporegime

    Joined: 18 Oct 2002

    Posts: 29,113

    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();
     
  3. GeX

    Soldato

    Joined: 17 Dec 2002

    Posts: 6,489

    Location: Manchester

    it's so obvious now, and i feel very silly. thanks again :)