Click here to Skip to main content
15,894,137 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Registry Manipulation - Odd behaviour Pin
Luc Pattyn23-Jul-09 0:20
sitebuilderLuc Pattyn23-Jul-09 0:20 
Question[Message Deleted] Pin
ksss_maheshece22-Jul-09 3:21
ksss_maheshece22-Jul-09 3:21 
AnswerRe: How can Embed a xml file? Pin
led mike22-Jul-09 5:49
led mike22-Jul-09 5:49 
GeneralRe: How can Embed a xml file? Pin
Mark Salsbery22-Jul-09 6:10
Mark Salsbery22-Jul-09 6:10 
GeneralRe: How can Embed a xml file? Pin
led mike22-Jul-09 6:12
led mike22-Jul-09 6:12 
GeneralRe: How can Embed a xml file? Pin
Mark Salsbery22-Jul-09 6:23
Mark Salsbery22-Jul-09 6:23 
GeneralRe: How can Embed a xml file? [modified] Pin
led mike22-Jul-09 6:46
led mike22-Jul-09 6:46 
QuestionXml Serializer - Default namespace on top-level Element Pin
Martijn Boeker21-Jul-09 20:14
Martijn Boeker21-Jul-09 20:14 
Hi,

I use the XmlSerializer and I'm looking for a way to set the default XML namespace on the top level Element. The correct way to do this, I hoped, was to specify this in an XmlType attribibute on the top level class. However, the namespace is only applied to the children of this class. For example, see the C# code below that serializes a simple nested structure:

// Contained class.
    public class Circle
    {
    }

    // Container class.
    [XmlType(Namespace="http://mbshapes.com")] // Why does the Shapes element not use this namespace?
    public class Shapes
    {
        private Circle _circle = new Circle();

        public Circle Circle
        {
            get
            {
                return _circle;
            }
            set
            {
                _circle = value;
            }
        }
    }

    // Serialize Shapes object.
    public class SerializeTest
    {
        public static void Serialize()
        {
            // Create Shapes object.
            Shapes shapes = new Shapes();

            // Open file.
            using (TextWriter textWriter = new StreamWriter("Shapes.xml"))
            {                
                // Serialize.
                XmlSerializer xmlSerializer = new XmlSerializer(typeof(Shapes));
                xmlSerializer.Serialize(textWriter, shapes);
            }
        }
    }


The output is this:

<?xml version="1.0" encoding="utf-8"?>
<Shapes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Circle xmlns="http://mbshapes.com" />
</Shapes>


What I expected (and what I need), is something like this:

<?xml version="1.0" encoding="utf-8"?>
<Shapes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://mbshapes.com">
  <Circle />
</Shapes>


Am I doing something wrong? Or are there any work-arounds?

Thanks.
AnswerRe: Xml Serializer - Default namespace on top-level Element Pin
Mark Salsbery22-Jul-09 6:08
Mark Salsbery22-Jul-09 6:08 
GeneralRe: Xml Serializer - Default namespace on top-level Element Pin
Martijn Boeker22-Jul-09 8:17
Martijn Boeker22-Jul-09 8:17 
QuestionProblem in break point Pin
rinku soni 2321-Jul-09 1:28
rinku soni 2321-Jul-09 1:28 
AnswerRe: Problem in break point Pin
Baran M22-Jul-09 22:56
Baran M22-Jul-09 22:56 
Questionhow to change DataGridViewLinkColumn text property forselected row only ?? Pin
TARAK NATH ROY20-Jul-09 23:12
TARAK NATH ROY20-Jul-09 23:12 
AnswerRe: how to change DataGridViewLinkColumn text property forselected row only ?? Pin
Jack Vanderhorst23-Jul-09 16:15
Jack Vanderhorst23-Jul-09 16:15 
QuestionCrystal report print error when canceled by user Pin
Rakesh.tecnics20-Jul-09 11:18
Rakesh.tecnics20-Jul-09 11:18 
QuestionHow to get DPI Scaling number within .NET Framework [modified] Pin
fjparisIII20-Jul-09 6:17
fjparisIII20-Jul-09 6:17 
AnswerRe: How to get DPI Scaling number within .NET Framework Pin
Jimmanuel20-Jul-09 6:38
Jimmanuel20-Jul-09 6:38 
GeneralRe: How to get DPI Scaling number within .NET Framework Pin
fjparisIII20-Jul-09 7:40
fjparisIII20-Jul-09 7:40 
GeneralRe: How to get DPI Scaling number within .NET Framework Pin
Luc Pattyn20-Jul-09 8:33
sitebuilderLuc Pattyn20-Jul-09 8:33 
GeneralRe: How to get DPI Scaling number within .NET Framework Pin
fjparisIII20-Jul-09 12:05
fjparisIII20-Jul-09 12:05 
GeneralRe: How to get DPI Scaling number within .NET Framework Pin
Luc Pattyn20-Jul-09 12:13
sitebuilderLuc Pattyn20-Jul-09 12:13 
GeneralRe: How to get DPI Scaling number within .NET Framework Pin
fjparisIII20-Jul-09 13:20
fjparisIII20-Jul-09 13:20 
GeneralRe: How to get DPI Scaling number within .NET Framework Pin
Luc Pattyn20-Jul-09 13:51
sitebuilderLuc Pattyn20-Jul-09 13:51 
GeneralRe: How to get DPI Scaling number within .NET Framework Pin
fjparisIII20-Jul-09 14:03
fjparisIII20-Jul-09 14:03 
GeneralRe: How to get DPI Scaling number within .NET Framework Pin
Luc Pattyn20-Jul-09 14:09
sitebuilderLuc Pattyn20-Jul-09 14:09 

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.