Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Append to a file using XML Serialization? Easy way to do this?

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 7/20/2009 5:21:00 PM
RayLopez99 wrote:

> Can you post, in pseudo-code or words, how to generate a root element
> programically once you have nodes (fragments)?

Why "once you have nodes"? Why can't you simply write out the root 
element with your XmlWriter with writer.WriteStartElement("root") and 
then pass on that writer to your XmlSerializer?


> In one file, now how can you add a root element in an easy way?
> 
> Such as
> 
> <?xml version="1.0" ?>
> <MyRootElementHere>
> 
> // above 2 nodes go here
> 
> </MyRootElementHere>

XInclude (http://www.w3.org/TR/xinclude/) is a way to include stuff in 
XML but Microsoft does not support XInclude with its XML parsers. And I 
am currently not sure it would allow you include a fragment.

The ConformanceLevel.Fragment exists as an implementation of what the 
XML specification calls "external parsed entity" 
(http://www.w3.org/TR/xml/#NT-extParsedEnt). So to use that you need a 
DTD that defines an external entity and then you can reference that 
entity in your document:

<!DOCTYPE root [
<!ENTITY foo SYSTEM "XMLFile2.xml">
]>
<root>
   &foo;
</root>

where XMLFile2.xml then can look like this:

<?xml version="1.0" encoding="utf-8" ?>
<foo>1</foo>
<foo>2</foo>
<foo>3</foo>

To parse the main file with XmlReader and .NET 2.0 or later you need e.g.

             XmlReaderSettings settings = new XmlReaderSettings();
             settings.ProhibitDtd = false;
             using (XmlReader reader = XmlReader.Create(@"XMLFile1.xml", 
settings))
             {
                 while (reader.Read())
                 {
                     // access stuff here
                 }
             }

-- 

	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent