You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Minh Thang Dang <th...@hotmail.co.uk> on 2007/12/12 19:20:07 UTC

Problem when parsing MPEG-7 metadata with schemas

Hi all,

I want to parse some MPEG-7 metadata. I load the metadata file into a C string (char *) and use the following code to parse it. However, it causes an error which crashes the application. I cannot even know what error it is. Can you help me please. 

Thank you very much in advance.

Code: 

XMLPlatformUtils::Initialize();
XERCES_CPP_NAMESPACE::XMLGrammarPoolImpl mpGrammarPool = new XMLGrammarPoolImpl(XMLPlatformUtils::fgMemoryManager);
XERCES_CPP_NAMESPACE::XercesDOMParser parser= new XercesDOMParser(0, XMLPlatformUtils::fgMemoryManager, mpGrammarPool); 

XercesDOMParser::ValSchemes valScheme = XercesDOMParser::Val_Always;
mpParser->setValidationScheme(valScheme);
mpParser->setDoNamespaces(true);
mpParser->setDoSchema(true);
mpParser->setValidationSchemaFullChecking(true);
mpParser->setIncludeIgnorableWhitespace(false);

MemBufInputSource* memBufIS = new MemBufInputSource(
                                                                      (const XMLByte*)pXMLString, // pXMLString is the data to be parsed
                                                                      strlen(pXMLString),
                                                                      "FromString", 
                                                                      false);
 mpParser->parse(*memBufIS); // crash here


The content of the metadata file:



<Mpeg7 xmlns="urn:mpeg:mpeg7:schema:2001" 

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

       xmlns:mpeg7="urn:mpeg:mpeg7:schema:2001" 

       xsi:schemaLocation="urn:mpeg:mpeg7:schema:2001 Mpeg7-2001.xsd">

    <DescriptionMetadata>

        <Version>1.0</Version>

        <PrivateIdentifier>descriptionUnitExample</PrivateIdentifier>

    </DescriptionMetadata>

    <DescriptionUnit xsi:type="ScalableColorType" numOfCoeff="16" numOfBitplanesDiscarded="0">

        <Coeff> 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 </Coeff>

    </DescriptionUnit>

</Mpeg7>



The MPEG-7 Schemas are downloaded from: http://m7itb.nist.gov/M7Validation.html

Best regards

_________________________________________________________________
Get Hotmail on your mobile, text MSN to 63463!
http://mobile.uk.msn.com/pc/mail.aspx

Re: Problem when parsing MPEG-7 metadata with schemas

Posted by David Bertoni <db...@apache.org>.
Minh Thang Dang wrote:
> 
>> One other thing you might also want to check is make sure that the null
>> character is placed to mark the end of the string.
>>
>> Keith
>>
> The problem is this works with other metadata (e.g. Dublin Core) but not MPEG-7. By the way, if I don't have any MPEG-7 schema files, there's no problem.
> 
>>> Did you take a look at the sample applications to see how they are
>>> structured?  Off the top of my head, I would suggest you make sure you're
>>> catching exceptions, and that you've enabled exception handling, but those
>>> are just guesses.
>>>
>>> You should run your application in a debugger, to see where the crash
>>> occurs.  Unfortunately, you haven't provided nearly enough information for
>>> anyone to determine if you have a bug in your code, or there's something
>>> wrong in Xerces-C.
>>>
>>> Dave
> I tried to catch, something like:
> try {
>         mpParser->parse(*memBufIS);
>     } 
>     catch (const XMLException& toCatch)
>     {
>         return false;
>     }
>     catch (const DOMException& toCatch) {
>         return false;
>     }
>     catch (exception& e) {
>         return false;
>     }
> 
> but no exception can be catched. In fact, the error message is as follows:
> "Unhandled exception at 0x... in foo.exe: 0xC0000005: Access violation writing location 0x...."

OK, so your application is writing to memory it doesn't own.  If you run it 
in the debugger, the debugger will break when the write occurs, and you can 
see a stack trace.  From that point, you should be able to figure out the 
problem.

Dave

RE: Problem when parsing MPEG-7 metadata with schemas

Posted by Jesse Pelton <js...@PKC.com>.
I think someone mentioned earlier in this thread that there were UPA
(Unique Particle Attribution) problems with the schema.  Some people
dislike the UPA rules and ignore them (as discussed in
http://www.w3.org/2005/05/25-schema/microsoft.html); Xerces enforces
them.

-----Original Message-----
From: Minh Thang Dang [mailto:thangdang@hotmail.co.uk] 
Sent: Friday, December 14, 2007 3:08 PM
To: c-users@xerces.apache.org
Subject: RE: Problem when parsing MPEG-7 metadata with schemas




> Subject: RE: Problem when parsing MPEG-7 metadata with schemas
> Date: Thu, 13 Dec 2007 11:14:39 -0500
> From: jsp@PKC.com
> To: c-users@xerces.apache.org
> 
> I'm with Dave: your best bet is to run under a debugger and look at
> where it crashes.
> 
> Failing that, you might want to take a look at the DOMPrint sample.
On
> my machine, it parses and prints your sample document just fine (with
-n
> -s -f -v=always) if all the relevant schema docs are in the same
> directory.  This would seem to indicate some problem in your code.
It's
> not a perfect match, since DOMPrint operates on a file input source
> rather than a MemBufInputSource.  (Are you absolutely certain that
> strlen(pXMLString) is the actual size of your buffer?)
> 

I tried out the MemParse sample provided in the Xerces C package.
I replaced the XML string in the MemParse sample by my XML string. After
recompiled it, I run:
MemParse.exe -v=always -n -s -f

And got the following error:

Error at (file prodInfo, line 4, char 71): Complex type
'ShotEditingTemporalDeco
mpositionType' violates the Unique Particle Attribution rule in its
components '
CompositionTransition' and 'CompositionTransition'

Error at (file prodInfo, line 4, char 71): Complex type
'ShotEditingTemporalDeco
mpositionType' violates the Unique Particle Attribution rule in its
components '
CompositionTransitionRef' and 'CompositionTransitionRef'

Error at (file prodInfo, line 4, char 71): Complex type
'ShotEditingTemporalDeco
mpositionType' violates the Unique Particle Attribution rule in its
components '
CompositionShot' and 'CompositionShot'

Error at (file prodInfo, line 4, char 71): Complex type
'ShotEditingTemporalDeco
mpositionType' violates the Unique Particle Attribution rule in its
components '
CompositionShotRef' and 'CompositionShotRef'

Anyone got any clue for these errors?

Again, here is my XML string:

<Mpeg7 xmlns="urn:mpeg:mpeg7:schema:2001" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns:mpeg7="urn:mpeg:mpeg7:schema:2001" 
       xsi:schemaLocation="urn:mpeg:mpeg7:schema:2001 Mpeg7-2001.xsd">
     <DescriptionMetadata>
        <Version>1.0</Version>
        <PrivateIdentifier>descriptionUnitExample</PrivateIdentifier>
    </DescriptionMetadata>
    <DescriptionUnit xsi:type="ScalableColorType" numOfCoeff="16"
numOfBitplanesDiscarded="0">
        <Coeff> 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 </Coeff>
    </DescriptionUnit>
</Mpeg7>

The MPEG-7 XML Schema can be downloaded at:
http://m7itb.nist.gov/Mpeg7-2001.xsd

The MemParse sample is located at \xerces-c-src_2_8_0\samples\MemParse

Thank you very much. Best regards.

Minh Thang Dang



_________________________________________________________________
Fancy some celeb spotting? 
https://www.celebmashup.com

RE: Problem when parsing MPEG-7 metadata with schemas

Posted by Minh Thang Dang <th...@hotmail.co.uk>.


> Subject: RE: Problem when parsing MPEG-7 metadata with schemas
> Date: Thu, 13 Dec 2007 11:14:39 -0500
> From: jsp@PKC.com
> To: c-users@xerces.apache.org
> 
> I'm with Dave: your best bet is to run under a debugger and look at
> where it crashes.
> 
> Failing that, you might want to take a look at the DOMPrint sample.  On
> my machine, it parses and prints your sample document just fine (with -n
> -s -f -v=always) if all the relevant schema docs are in the same
> directory.  This would seem to indicate some problem in your code.  It's
> not a perfect match, since DOMPrint operates on a file input source
> rather than a MemBufInputSource.  (Are you absolutely certain that
> strlen(pXMLString) is the actual size of your buffer?)
> 

I tried out the MemParse sample provided in the Xerces C package.
I replaced the XML string in the MemParse sample by my XML string. After recompiled it, I run:
MemParse.exe -v=always -n -s -f

And got the following error:

Error at (file prodInfo, line 4, char 71): Complex type 'ShotEditingTemporalDeco
mpositionType' violates the Unique Particle Attribution rule in its components '
CompositionTransition' and 'CompositionTransition'

Error at (file prodInfo, line 4, char 71): Complex type 'ShotEditingTemporalDeco
mpositionType' violates the Unique Particle Attribution rule in its components '
CompositionTransitionRef' and 'CompositionTransitionRef'

Error at (file prodInfo, line 4, char 71): Complex type 'ShotEditingTemporalDeco
mpositionType' violates the Unique Particle Attribution rule in its components '
CompositionShot' and 'CompositionShot'

Error at (file prodInfo, line 4, char 71): Complex type 'ShotEditingTemporalDeco
mpositionType' violates the Unique Particle Attribution rule in its components '
CompositionShotRef' and 'CompositionShotRef'

Anyone got any clue for these errors?

Again, here is my XML string:

<Mpeg7 xmlns="urn:mpeg:mpeg7:schema:2001" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns:mpeg7="urn:mpeg:mpeg7:schema:2001" 
       xsi:schemaLocation="urn:mpeg:mpeg7:schema:2001 Mpeg7-2001.xsd">
     <DescriptionMetadata>
        <Version>1.0</Version>
        <PrivateIdentifier>descriptionUnitExample</PrivateIdentifier>
    </DescriptionMetadata>
    <DescriptionUnit xsi:type="ScalableColorType" numOfCoeff="16" numOfBitplanesDiscarded="0">
        <Coeff> 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 </Coeff>
    </DescriptionUnit>
</Mpeg7>

The MPEG-7 XML Schema can be downloaded at: http://m7itb.nist.gov/Mpeg7-2001.xsd

The MemParse sample is located at \xerces-c-src_2_8_0\samples\MemParse

Thank you very much. Best regards.

Minh Thang Dang



_________________________________________________________________
Fancy some celeb spotting? 
https://www.celebmashup.com

RE: Problem when parsing MPEG-7 metadata with schemas

Posted by Jesse Pelton <js...@PKC.com>.
I'm with Dave: your best bet is to run under a debugger and look at
where it crashes.

Failing that, you might want to take a look at the DOMPrint sample.  On
my machine, it parses and prints your sample document just fine (with -n
-s -f -v=always) if all the relevant schema docs are in the same
directory.  This would seem to indicate some problem in your code.  It's
not a perfect match, since DOMPrint operates on a file input source
rather than a MemBufInputSource.  (Are you absolutely certain that
strlen(pXMLString) is the actual size of your buffer?)

-----Original Message-----
From: Minh Thang Dang [mailto:thangdang@hotmail.co.uk] 
Sent: Thursday, December 13, 2007 8:39 AM
To: c-users@xerces.apache.org
Subject: RE: Problem when parsing MPEG-7 metadata with schemas


> At the very least, you should specify, exactly, one schema file that>
shows your problem.  Without a concrete test case, nobody can help you.>
> Dale> The shema file is MPEG7-2001.xsd which can be downloaded at
http://m7itb.nist.gov/Mpeg7-2001.xsdMy metadata file has the following
content:<Mpeg7 xmlns="urn:mpeg:mpeg7:schema:2001" 
 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 
       xmlns:mpeg7="urn:mpeg:mpeg7:schema:2001" 
 
       xsi:schemaLocation="urn:mpeg:mpeg7:schema:2001 Mpeg7-2001.xsd">
 
    <DescriptionMetadata>
 
        <Version>1.0</Version>
 
        <PrivateIdentifier>descriptionUnitExample</PrivateIdentifier>
 
    </DescriptionMetadata>
 
    <DescriptionUnit xsi:type="ScalableColorType" numOfCoeff="16"
numOfBitplanesDiscarded="0">
 
        <Coeff> 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 </Coeff>
 
    </DescriptionUnit>
 
</Mpeg7>

If I don't put the mpeg7-2001.xsd in the same directory as the metadata
file, my code doesn't crash the application

> OK, so your application is writing to memory it doesn't own.  If you
run it 
> in the debugger, the debugger will break when the write occurs, and
you can 
> see a stack trace.  From that point, you should be able to figure out
the 
> problem.
> 

The problem occurs as soon as I call mpParser->parse(*memBufIS). I
cannot work it out, so I posted the question here.

The strangest thing is my code works well with other metadata sets (e.g.
Dublin Core). Again, here is my code:

XMLPlatformUtils::Initialize();
XERCES_CPP_NAMESPACE::XMLGrammarPoolImpl* GrammarPool = new
XMLGrammarPoolImpl(XMLPlatformUtils::fgMemoryManager);
XERCES_CPP_NAMESPACE::XercesDOMParser* parser= new XercesDOMParser(0,
XMLPlatformUtils::fgMemoryManager, GrammarPool); 

XercesDOMParser::ValSchemes valScheme = XercesDOMParser::Val_Always;
parser->setValidationScheme(valScheme);
parser->setDoNamespaces(true);
parser->setDoSchema(true);
parser->setValidationSchemaFullChecking(true);
parser->setIncludeIgnorableWhitespace(false);

MemBufInputSource* memBufIS = new MemBufInputSource(

	
(const XMLByte*)pXMLString, // pXMLString is the data to be parsed
 
strlen(pXMLString),
 
"FromString", 
 
false);
 parser->parse(*memBufIS); // CRASH here

The error message is:
"Unhandled exception at 0x... in foo.exe: 0xC0000005: Access violation
writing location 0x...."
 
_________________________________________________________________
Fancy some celeb spotting? 
https://www.celebmashup.com

RE: Problem when parsing MPEG-7 metadata with schemas

Posted by Minh Thang Dang <th...@hotmail.co.uk>.
> At the very least, you should specify, exactly, one schema file that> shows your problem.  Without a concrete test case, nobody can help you.> > Dale> The shema file is MPEG7-2001.xsd which can be downloaded at http://m7itb.nist.gov/Mpeg7-2001.xsdMy metadata file has the following content:<Mpeg7 xmlns="urn:mpeg:mpeg7:schema:2001" 
 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 
       xmlns:mpeg7="urn:mpeg:mpeg7:schema:2001" 
 
       xsi:schemaLocation="urn:mpeg:mpeg7:schema:2001 Mpeg7-2001.xsd">
 
    <DescriptionMetadata>
 
        <Version>1.0</Version>
 
        <PrivateIdentifier>descriptionUnitExample</PrivateIdentifier>
 
    </DescriptionMetadata>
 
    <DescriptionUnit xsi:type="ScalableColorType" numOfCoeff="16" numOfBitplanesDiscarded="0">
 
        <Coeff> 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 </Coeff>
 
    </DescriptionUnit>
 
</Mpeg7>

If I don't put the mpeg7-2001.xsd in the same directory as the metadata file, my code doesn't crash the application

> OK, so your application is writing to memory it doesn't own.  If you run it 
> in the debugger, the debugger will break when the write occurs, and you can 
> see a stack trace.  From that point, you should be able to figure out the 
> problem.
> 

The problem occurs as soon as I call mpParser->parse(*memBufIS). I cannot work it out, so I posted the question here.

The strangest thing is my code works well with other metadata sets (e.g. Dublin Core). Again, here is my code:

XMLPlatformUtils::Initialize();
XERCES_CPP_NAMESPACE::XMLGrammarPoolImpl* GrammarPool = new XMLGrammarPoolImpl(XMLPlatformUtils::fgMemoryManager);
XERCES_CPP_NAMESPACE::XercesDOMParser* parser= new XercesDOMParser(0, XMLPlatformUtils::fgMemoryManager, GrammarPool); 

XercesDOMParser::ValSchemes valScheme = XercesDOMParser::Val_Always;
parser->setValidationScheme(valScheme);
parser->setDoNamespaces(true);
parser->setDoSchema(true);
parser->setValidationSchemaFullChecking(true);
parser->setIncludeIgnorableWhitespace(false);

MemBufInputSource* memBufIS = new MemBufInputSource(                                            
								      (const XMLByte*)pXMLString, // pXMLString is the data to be parsed
                                                                      strlen(pXMLString),
                                                                      "FromString", 
                                                                      false);
 parser->parse(*memBufIS); // CRASH here

The error message is:
"Unhandled exception at 0x... in foo.exe: 0xC0000005: Access violation writing location 0x...."
 
_________________________________________________________________
Fancy some celeb spotting? 
https://www.celebmashup.com

RE: Problem when parsing MPEG-7 metadata with schemas

Posted by Dale Worley <dw...@pingtel.com>.
On Wed, 2007-12-12 at 19:54 +0000, Minh Thang Dang wrote:
> 
> > One other thing you might also want to check is make sure that the null
> > character is placed to mark the end of the string.
> > 
> > Keith
> > 
> The problem is this works with other metadata (e.g. Dublin Core) but
> not MPEG-7. By the way, if I don't have any MPEG-7 schema files,
> there's no problem.

At the very least, you should specify, exactly, one schema file that
shows your problem.  Without a concrete test case, nobody can help you.

Dale



Re: Problem when parsing MPEG-7 metadata with schemas

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Hi,

Minh Thang Dang <th...@hotmail.co.uk> writes:

> The problem is this works with other metadata (e.g. Dublin Core) but
> not MPEG-7. By the way, if I don't have any MPEG-7 schema files,
> there's no problem.

Last time I worked with the MPEG-7 schemas, they had a UPA violation,
see the thread starting at:

http://www.codesynthesis.com/pipermail/xsd-users/2006-November/000602.html

Your application is crashing most likely because you are not detecting
the error and trying to use a DOM document pointer which is NULL. Or
something along these lines.

Boris

-- 
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis.com
Open-Source, Cross-Platform C++ XML Data Binding

RE: Problem when parsing MPEG-7 metadata with schemas

Posted by Minh Thang Dang <th...@hotmail.co.uk>.

> One other thing you might also want to check is make sure that the null
> character is placed to mark the end of the string.
> 
> Keith
> 
The problem is this works with other metadata (e.g. Dublin Core) but not MPEG-7. By the way, if I don't have any MPEG-7 schema files, there's no problem.

> > Did you take a look at the sample applications to see how they are
> > structured?  Off the top of my head, I would suggest you make sure you're
> > catching exceptions, and that you've enabled exception handling, but those
> > are just guesses.
> >
> > You should run your application in a debugger, to see where the crash
> > occurs.  Unfortunately, you haven't provided nearly enough information for
> > anyone to determine if you have a bug in your code, or there's something
> > wrong in Xerces-C.
> >
> > Dave
>
I tried to catch, something like:
try {
        mpParser->parse(*memBufIS);
    } 
    catch (const XMLException& toCatch)
    {
        return false;
    }
    catch (const DOMException& toCatch) {
        return false;
    }
    catch (exception& e) {
        return false;
    }

but no exception can be catched. In fact, the error message is as follows:
"Unhandled exception at 0x... in foo.exe: 0xC0000005: Access violation writing location 0x...."

Many thanks.


_________________________________________________________________
Get Hotmail on your mobile, text MSN to 63463!
http://mobile.uk.msn.com/pc/mail.aspx

Re: Problem when parsing MPEG-7 metadata with schemas

Posted by Keith Mendoza <pa...@gmail.com>.
One other thing you might also want to check is make sure that the null
character is placed to mark the end of the string.

Keith

On Dec 12, 2007 10:39 AM, David Bertoni <db...@apache.org> wrote:

> Minh Thang Dang wrote:
> > Hi all,
> >
> > I want to parse some MPEG-7 metadata. I load the metadata file into a C
> string (char *) and use the following code to parse it. However, it causes
> an error which crashes the application. I cannot even know what error it is.
> Can you help me please.
>
> Did you take a look at the sample applications to see how they are
> structured?  Off the top of my head, I would suggest you make sure you're
> catching exceptions, and that you've enabled exception handling, but those
> are just guesses.
>
> You should run your application in a debugger, to see where the crash
> occurs.  Unfortunately, you haven't provided nearly enough information for
> anyone to determine if you have a bug in your code, or there's something
> wrong in Xerces-C.
>
> Dave
>

Re: Problem when parsing MPEG-7 metadata with schemas

Posted by David Bertoni <db...@apache.org>.
Minh Thang Dang wrote:
> Hi all,
> 
> I want to parse some MPEG-7 metadata. I load the metadata file into a C string (char *) and use the following code to parse it. However, it causes an error which crashes the application. I cannot even know what error it is. Can you help me please. 

Did you take a look at the sample applications to see how they are 
structured?  Off the top of my head, I would suggest you make sure you're 
catching exceptions, and that you've enabled exception handling, but those 
are just guesses.

You should run your application in a debugger, to see where the crash 
occurs.  Unfortunately, you haven't provided nearly enough information for 
anyone to determine if you have a bug in your code, or there's something 
wrong in Xerces-C.

Dave