Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have this c# code :
VB
new XElement("Zone",
                         new XElement("gmlBoundedBy",

                             new XElement("gmlBox",
                                 new XElement("gmlCoord1",

                                     new XElement("gmlX", Planaanvraag_Zone_gml_boundedBy_gml_Box_gml_coord_gml_X1),
                                     new XElement("gmlY", Planaanvraag_Zone_gml_boundedBy_gml_Box_gml_coord_gml_Y1)
                                     ),
                                 new XElement("gmlCoord2",
                                      new XElement("gmlX", Planaanvraag_Zone_gml_boundedBy_gml_Box_gml_coord_gml_X2),
                                     new XElement("gmlY", Planaanvraag_Zone_gml_boundedBy_gml_Box_gml_coord_gml_Y2)
                                     )
                                 )

                             ),



and i want this output i used everything but it is not working :
HTML
<pre lang="xml"><gml:boundedBy>
      <gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#31300">
        <gml:coord>
        <gml:X>144287.60</gml:X>
        <gml:Y>170609.06</gml:Y>
        </gml:coord>
        <gml:coord>
        <gml:X>144485.51</gml:X>
        <gml:Y>170912.33</gml:Y>
        </gml:coord>
      </gml:Box>
      </gml:boundedBy>

HTML
<pre lang="HTML"><pre lang="HTML">


can anyone help me how to add colons in xml format ?
Posted
Comments
John C Rayan 23-Feb-15 8:33am    
Are you aware that : is reserved for namespaces in XML? can you explain why you want : in the element name. Do you want to include namespace?
Hesham el Masry 23-Feb-15 8:47am    
yes i want to include name space but i dont know how
John C Rayan 23-Feb-15 16:52pm    
Please mark the solution as accepted if it solves your problem
Hesham el Masry 24-Feb-15 0:35am    
sure mr john :)

1 solution

Change according to your need. You can see the namespace is added with : in the output.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {

            XNamespace gml = "http://www.samplens.com";

            XElement x = new XElement(gml + "Box", new XAttribute(XNamespace.Xmlns + "gml", gml.NamespaceName), new XElement(gml + "coord","some content" ));

Console.WriteLine(x);
Console.ReadLine();



        }
    }
}
 
Share this answer
 
v3
Comments
Hesham el Masry 24-Feb-15 0:35am    
Oh ! thank you so much now i undestand how to make it , thank you :)
John C Rayan 24-Feb-15 4:56am    
Glad it helped you. Happy to help.

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