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="...">Cont ent</test:info>
<test:info date="...">Othe r content</test:info>
....
I have some .net 1.1 code that reads the nodes from the file one by one:
FileStream stream = new FileStream(@"fi le.xml", FileMode.Open);
XmlNameTable nt = new NameTable( );
XmlNamespaceMan ager nsMgr = new XmlNamespaceMan ager(nt);
nsMgr.AddNamesp ace("test", "http://sturmnet.org/ns/test");
XmlParserContex t context = new XmlParserContex t(nt, nsMgr, null,
XmlSpace.None);
XmlTextReader reader = new XmlTextReader(s tream, XmlNodeType.Ele ment,
context);
XmlDocument doc = new XmlDocument( );
while (!reader.EOF) {
XmlNode node = doc.ReadNode(re ader);
// do something with the node
}
Now, using .net 2.0, docs say I'm supposed to have my XmlReader created
by XmlReader.Creat e 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
XmlReaderSettin gs settings = new XmlReaderSettin gs( );
settings.Confor manceLevel = ConformanceLeve l.Fragment;
XmlReader reader = XmlReader.Creat e(@"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