Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. xml serialisation

xml serialisation

Scheduled Pinned Locked Moved C#
xmldatabasehelptutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JoZ CaVaLLo
    wrote on last edited by
    #1

    Hi... I need to create an XML file from an object, and I have to obtain the the following root element:

    <declaresalary>
    xmlns:st="http://www.swissdec.ch/schema/sd/20051002/SalaryDeclarationServiceTypes"
    xmlns:ct="http://www.swissdec.ch/schema/sd/20051002/SalaryDeclarationContainer"
    xmlns:sd="http://www.swissdec.ch/schema/sd/20051002/SalaryDeclaration"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    ct:requestcontext
    ...

    My problem is that I can't figure out how to set all those xmlns attributes. Can somebody give me an hint please?

    Life is not short... the problem is only how you organize yourself

    L J 2 Replies Last reply
    0
    • J JoZ CaVaLLo

      Hi... I need to create an XML file from an object, and I have to obtain the the following root element:

      <declaresalary>
      xmlns:st="http://www.swissdec.ch/schema/sd/20051002/SalaryDeclarationServiceTypes"
      xmlns:ct="http://www.swissdec.ch/schema/sd/20051002/SalaryDeclarationContainer"
      xmlns:sd="http://www.swissdec.ch/schema/sd/20051002/SalaryDeclaration"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      ct:requestcontext
      ...

      My problem is that I can't figure out how to set all those xmlns attributes. Can somebody give me an hint please?

      Life is not short... the problem is only how you organize yourself

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      JoZ CaVaLLo wrote:

      My problem is that I can't figure out how to set all those xmlns attributes.

      System.Xml.Serialization.XmlSerializerNamespaces i think

      xacc.ide - now with TabsToSpaces support
      IronScheme - 1.0 alpha 4a out now (29 May 2008)

      1 Reply Last reply
      0
      • J JoZ CaVaLLo

        Hi... I need to create an XML file from an object, and I have to obtain the the following root element:

        <declaresalary>
        xmlns:st="http://www.swissdec.ch/schema/sd/20051002/SalaryDeclarationServiceTypes"
        xmlns:ct="http://www.swissdec.ch/schema/sd/20051002/SalaryDeclarationContainer"
        xmlns:sd="http://www.swissdec.ch/schema/sd/20051002/SalaryDeclaration"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        ct:requestcontext
        ...

        My problem is that I can't figure out how to set all those xmlns attributes. Can somebody give me an hint please?

        Life is not short... the problem is only how you organize yourself

        J Offline
        J Offline
        JoZ CaVaLLo
        wrote on last edited by
        #3

        the right use of XmlSerializerNamespaces is

        XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
        namespaces.Add("ct", "http://www.swissdec.ch/schema/sd/20051002/SalaryDeclarationContainer");
        namespaces.Add("sd", "http://www.swissdec.ch/schema/sd/20051002/SalaryDeclaration");
        namespaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");

        System.IO.File.Delete(pPathToGenerate);
        fs = new System.IO.FileStream(pPathToGenerate, System.IO.FileMode.Create);
        writer = new System.Xml.Serialization.XmlSerializer(typeof(XmlSerializatorItems.DeclareSalary));
        writer.Serialize(fs, oDeclare, namespaces);
        fs.Close();

        In the object to serialize you have to specify the namespace for each field.

        Life is not short... the problem is only how you organize yourself

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups