I have an XML file that contains fragments, meaning there's no root
element. Node names are in my own "test" namespace. Looks like this:
<test:info date="...">Content</test:info>
<test:info date="...">Other content</test:info>
....
I have some .net 1.1 code that reads the nodes from the file one by one:
FileStream stream = new FileStream(@"file.xml", FileMode.Open);
XmlNameTable nt = new NameTable( );
XmlNamespaceManager nsMgr = new XmlNamespaceManager(nt);
nsMgr.AddNamespace("test", "http://sturmnet.org/ns/test");
XmlParserContext context = new XmlParserContext(nt, nsMgr, null,
XmlSpace.None);
XmlTextReader reader = new XmlTextReader(stream, XmlNodeType.Element,
context);
XmlDocument doc = new XmlDocument( );
while (!reader.EOF) {
XmlNode node = doc.ReadNode(reader);
// do something with the node
}
Now, using .net 2.0, docs say I'm supposed to have my XmlReader created
by XmlReader.Create instead of creating it myself. I was also hoping to
find a replacement for the reading of the nodes, because using that
XmlDocument, that's useless otherwise, just doesn't look like the most
elegant solution.
I fiddled around with this for a while, starting with
XmlReaderSettings settings = new XmlReaderSettings( );
settings.ConformanceLevel = ConformanceLevel.Fragment;
XmlReader reader = XmlReader.Create(@"file.xml", settings);
while (!reader.EOF) {
reader.Read();
// now where's my node?
}
First problem: I get an error message saying the "test" namespace is
unknown and I have no idea where I'm supposed to stick my namespace in
this model.
So, what's the PC way to get this done in .net 2.0?
Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog