Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: Append to a file using XML Serialization? Easy way to do this? >Thread Next - Re: Append to a file using XML Serialization? Easy way to do this? Re: Append to a file using XML Serialization? Easy way to do this?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/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
