Hi Robert,
I need to read an XML file and thought of using osgDB::XmlParser to do
it. Calling this:
osgDB::readXmlFile(filename);
results in "Could not open XML file: somefilename.xml". But the file is
there and some simple code using an ifstream to read the file (using the
same filename variable) works. So I started looking into the code. One
thing strikes me as weird in osgDB::readXmlFile() :
// ...
XmlNode::Input input;
input.open(foundFile);
if (!input)
{
// error "Could not open XML file: ... "
}
input.readAllDataIntoBuffer();
// ...
XmlNode::Input::Input() initializes _currentPos to 0. Then
input.open(foundFile) calls ifstream::open(foundFile.c_str()) so up to
there, all's well. But then XmlNode::Input::operator bool() is this:
operator bool () const { return _currentPos<_buffer.size(); }
Now, nothing has touched _buffer yet (readAllDataIntoBuffer() below the
error is what fills it) so its size is 0, and _currentPos was set to 0
in the ctor, so this check ( _currentPos<_buffer.size(); ) will
obviously return false.
I don't think that's what is intended... is it? I don't see how this
code could work at all, won't it error out every time?
I searched for readXmlFile in the OSG sources and didn't get any
results, is this used at all?
A change that makes it work would be, for example:
operator bool () const { return (_fin.good() && _currentPos == 0) ||
_currentPos<_buffer.size(); }
What's funny is that the XmlParser code is used in the present3D
application (and I assume the p3d plugin too) but it doesn't use
readXmlFile at all and just bypasses the check:
osgDB::XmlNode::Input input;
input.open(fileName);
input.readAllDataIntoBuffer();
Is this intended? Why would OSG not use its own helper function?
------------------
Once I do this in my code (awaiting a good fix to readXmlFile() ), I get
errors "end tag is not matched correctly" for items like:
<item someattribute="somevalue" />
This is valid XML syntax, but is it not supported by the XmlParser? I
could add support for it, but it seems weird that it's not supported...
Thanks,
J-S
--
______________________________________________________
Jean-Sebastien Guay jean-sebastien.g...@cm-labs.com
http://www.cm-labs.com/
http://whitestar02.webhop.org/
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org