Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
I have a problems after try execute: 1. System.Xml.XmlException: The ':' character, hexadecimal value 0x3A, cannot be included in a name
Please some one help me

My code is:


    XDocument document = new XDocument(
            new XDeclaration("1.0", "utf-8", "yes"),
            new XElement("rss", new XAttribute(XNamespace.Xmlns + "media", "http://m.xyz.com/rss/"), new XAttribute("version", "2.0"),

                new XElement("channel",
                    new XAttribute("vendor", "ABC"),
                    new XAttribute("lastpublishdate", DateTime.Now.ToString("dd/MM/yyyy hh:mm"))),

                    new XElement("title", "Videos"),
                    new XElement("media:thumbnail", new XAttribute("width", x.width.ToString().Trim()), new XAttribute("height", x.height.ToString().Trim())),
        )
 );



My Expected O/P-

<rss xmlns:media="http://m.xyz.com/rss/" version="2.0">
<channel vendor="ABC" lastpublishdate="05/12/2013 01:02"/>
<title>Videos</title>
<media:thumbnail width="180" height="75" />
</rss>
Posted

1 solution

Hi
Try this code..



XML
string x = "55"; 

            XNamespace aw = "http://m.xyz.com/rss/";
            XDocument document = new XDocument(
                       new XDeclaration("1.0", "utf-8", "yes"), new XElement("rss", new XAttribute(XNamespace.Xmlns + "media", "http://m.xyz.com/rss/"), new XAttribute("version", "2.0"),

                           new XElement("channel",
                               new XAttribute("vendor", "ABC"),
                               new XAttribute("lastpublishdate", DateTime.Now.ToString("dd/MM/yyyy hh:mm"))),

                               new XElement("title", "Videos"),
                               new XElement(aw + "thumbnail", new XAttribute("width", x.Trim()), new XAttribute("height", x.Trim()))
                   )
            );



COde Reference :: http://forums.asp.net/t/1320854.aspx[^]
 
Share this answer
 
Comments
anurag.netdeveloper 5-Dec-13 4:39am    
Thanks Karthik for the reply but using this above code, im getting this o/p -

<thumbnail xmlns="http://m.xyz.com/rss/" width="180" height="75" />

and what i want should be look like this - <media:thumbnail width="180" height="75">
Karthik_Mahalingam 5-Dec-13 4:46am    
send your code..

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