[xsd-users] Why this error?
Al Niessner
Al.Niessner at jpl.nasa.gov
Thu Mar 8 18:02:09 EST 2007
This seems to be an error propagating up from xceres-c 2.7. It does not
something about the line
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
I have no idea what it thinks is wrong, but from the message I would
guess that its failure point is '=' at column 13. Given my quality at
parsing XML, I would say that it is a valid line of XML. JaxB and
generateDS would agree.
On Thu, 2007-03-08 at 13:48 -0800, Al Niessner wrote:
> Message does not help me much more:
>
> :1:13 error: Unterminated processing instruction
>
> If it is referring to the XML, all the tags that I see are terminated.
> Does it mean something different to you?
>
> On Thu, 2007-03-08 at 09:42 +0200, Boris Kolpackov wrote:
> > Hi Al,
> >
> > Al Niessner <Al.Niessner at jpl.nasa.gov> writes:
> >
> > > I then wrote a bunch of C++ code that looks very similar to my Java and
> > > Python code to parse some XML. It did not work at all. I get this error
> > > message:
> > >
> > > terminate called after throwing an instance of
> > > 'xsd::cxx::tree::parsing<char>'
> > > what(): instance document parsing failed.
> >
> > It is usually a good idea to catch the exception and print it to get
> > a better idea about what went wrong. Here is what I did:
> >
> > try
> > {
> > msg = ExternalTool (ss, xml_schema::flags::dont_validate);
> > }
> > catch (const xml_schema::exception& e)
> > {
> > std::cerr << e << std::endl;
> > }
> >
> > After this change I got a more descriptive error:
> >
> > 1:13 error: Unterminated processing instruction
> >
> > For some reason it does not like your XML declaration
> > (<?xml version="1.0" encoding="UTF-8" standalone="yes"?>) since that's
> > the only processing instruction in this document.
> >
> > Because you are first reading the contents of the file into a string
> > buffer, let's check if the XML is still good in that buffer. I added
> >
> > std::cout << fullText << std::endl;
> >
> > Before the above code. It prints:
> >
> > <?xmlversion="1.0"encoding="UTF-8"standalone="yes"?><ExternalTool>...
> >
> > The XML declaration does not look right anymore: all whitespaces are
> > gone. Looking at the code that fills the buffer we can see what's
> > going on:
> >
> > while (!fin.eof())
> > {
> > fin >> buffer;
> > fullText += buffer;
> > }
> >
> > fin >> buffer reads one word at a time, stripping leading and trailing
> > whitespaces. Here is a version that reads in an exact copy of the file.
> > It is also a bit more efficient:
> >
> > fin.open ("msg.xml", std::ios::in | std::ios::ate);
> > std::size_t size (fin.tellg ());
> > fin.seekg (0, std::ios::beg);
> >
> > fullText.reserve (size);
> >
> > while (size != 0 && !fin.eof ())
> > {
> > char buf[1024];
> > fin.read (buf, size < sizeof (buf) ? size : sizeof (buf));
> > std::size_t n = fin.gcount ();
> >
> > fullText.append (buf, n);
> > size -= n;
> > }
> >
> > fin.close();
> >
> > After making this change the file parses without any problems.
> > You probably know that, but just in case, you can parse the file
> > directly without first reading it into a buffer. Both:
> >
> > msg = ExternalTool ("msg.xml", xml_schema::flags::dont_validate);
> >
> > and
> >
> > fin.open ("msg.xml");
> > msg = ExternalTool (fin, xml_schema::flags::dont_validate);
> > fin.close();
> >
> > work.
> >
> >
> > hth,
> > -boris
--
Al Niessner
818.354.0859
All opinions stated above are mine and do not necessarily reflect those
of JPL or NASA.
--------
| dS | >= 0
--------
More information about the xsd-users
mailing list