View Full Version : xml reader
mickey
12th January 2008, 21:51
Hello,
I need to parse a text file similar to xml file with C# but it has special tag like <myTag1:text>, <myTag2:Other>; XmlreaderText() of C# fails to parse those tags; I tried to install MSXML parser hoping it helps me, but I don't know how use it and if I've installed it properly; How can I solve my problem? Is MSXML a right solution? Other solution with C# (important: at moment I should skip QT features)
jacek
12th January 2008, 22:17
myTag1 and myTag2 look like XML namespaces. How exactly C# parser "fails to parse those tags"?
mickey
12th January 2008, 22:40
XmlTextReader tr = new XmlTextReader(path_and_File);
while (tr.Read()) {
//here I need to extract tag name;
//all goes fine until it see <tag1:Other>
//an exception raises saying that tag1 namespace isn't declare;
}
Probabily you understand the core........how do I use those type of tags?
jacek
12th January 2008, 23:15
You can try to set the Namespaces attribute to false and see what happens. Another option is to reimplement LookupNamespace() method and make it always return some URI.
mickey
12th January 2008, 23:39
With first
tr.Namespaces = false;
it works;
Any more explaination about second option, please?
jacek
13th January 2008, 18:37
Any more explaination about second option, please?
You have to declare namespaces before you can use them and you do this by adding special attribute:
<element xmlns:namespace="http://unique.URI.for/namespace">
...
<namespace:someOtherElement />
...
</element>
This way the parser will know what "namespace" is. Such mechanism is useful when you embed one XML document in another (for example XHTML tags in XSLT stylesheet or SVG in DocBook) and still want to have a possibility to validate your document.
The idea was to trick the parser and make it think, that it has already seen the namespace declaration.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.