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 Fragment Serialization [modified]

XML Fragment Serialization [modified]

Scheduled Pinned Locked Moved C#
xmljsonhelpquestion
5 Posts 2 Posters 1 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.
  • T Offline
    T Offline
    Tristan Rhodes
    wrote on last edited by
    #1

    I'm working on an existing system which operates on large XML files, but the areas of interest at any given point are relatively small. So i've begun moving the small regions across to an object model, which i will serialize into / out of the existing XML document in the appropriate places in fragments. My problem is, the XMLSerializer generates the XMLFile Declaration and NameSpace attributes in the root element, which makes the end result a complete XML Document, as opposed to a fragment that is part of a larger doc. Is there any way to avoid the generation / requirement of the XML Serialization attributes so that it is actualy a Fragment? Cheers Tris

    D 1 Reply Last reply
    0
    • T Tristan Rhodes

      I'm working on an existing system which operates on large XML files, but the areas of interest at any given point are relatively small. So i've begun moving the small regions across to an object model, which i will serialize into / out of the existing XML document in the appropriate places in fragments. My problem is, the XMLSerializer generates the XMLFile Declaration and NameSpace attributes in the root element, which makes the end result a complete XML Document, as opposed to a fragment that is part of a larger doc. Is there any way to avoid the generation / requirement of the XML Serialization attributes so that it is actualy a Fragment? Cheers Tris

      D Offline
      D Offline
      Dustin Metzgar
      wrote on last edited by
      #2

      When you write from the XmlSerializer, you can use an XmlWriter (as a TextWriter). Use the static Create method off of XmlWriter to make a writer that has XmlWriterSettings. Using the settings, you can tell it to not put the declarations.

      T 1 Reply Last reply
      0
      • D Dustin Metzgar

        When you write from the XmlSerializer, you can use an XmlWriter (as a TextWriter). Use the static Create method off of XmlWriter to make a writer that has XmlWriterSettings. Using the settings, you can tell it to not put the declarations.

        T Offline
        T Offline
        Tristan Rhodes
        wrote on last edited by
        #3

        Thanks Dustin, that's just the ticket. One last thing - is it possible to remove the xmlns:xsi and xmlns:xsd attributes using settings? I've had a play around, but they are staying put. Cheers Tris

        D 2 Replies Last reply
        0
        • T Tristan Rhodes

          Thanks Dustin, that's just the ticket. One last thing - is it possible to remove the xmlns:xsi and xmlns:xsd attributes using settings? I've had a play around, but they are staying put. Cheers Tris

          D Offline
          D Offline
          Dustin Metzgar
          wrote on last edited by
          #4

          That one's a bit tougher. Are you using namespaces in the attributes on the type?

          Logifusion[^]

          1 Reply Last reply
          0
          • T Tristan Rhodes

            Thanks Dustin, that's just the ticket. One last thing - is it possible to remove the xmlns:xsi and xmlns:xsd attributes using settings? I've had a play around, but they are staying put. Cheers Tris

            D Offline
            D Offline
            Dustin Metzgar
            wrote on last edited by
            #5

            I finally got to a dev environment where I could test it. There really isn't a way to wipe those attributes off of there, which I think is a very frustrating part of using XmlSerializer. Some of the tactics I've taken in the past are to implement IXmlSerializable (which isn't fun because you have to read and write from the xml stream yourself) or to load the serialized xml into an XmlDocument and remove the namespaces manually. I'm not sure if MVPXML[^] has done anything to handle this but you may want to check it out.

            Logifusion[^]

            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