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 Roberto Rigamonti <ro...@gmail.com> on 2008/05/05 15:44:31 UTC

Writing an XML Schema using Xerces and C++

Hello, I'm trying to create a schema file from scratch using Xerces in
C++, but the documentation in the net seems to me very obscure
(excluding Doxygen-generated documentation, I haven't found much
examples other than those included in the Xerces pack, and several
methods are presented for writing an XML file, but none works for me
because they bloat the result with DOCTYPE/other unwanted stuff).
I'd like to have a result like the following one:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            elementFormDefault="qualified">
  <xsd:include schemaLocation="lib3DVisLine.xsd"/>
  <xsd:include schemaLocation="lib3DVisPoint.xsd"/>

  <xsd:element name="visor">
    <xsd:complexType>
      <xsd:choice minOccurs="0" maxOccurs="unbounded">
	  <xsd:element name="line" type="lib3DVisLine"/>
	  <xsd:element name="point" type="lib3DVisPoint"/>
      </xsd:choice>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

I've tried many approaches, but the resulting code, even if it compiles
successfully, throws a DOMException or segfaults without any good reason...
Does anyone know a "good way" to create a XML Schema from scratch?
Thanks in advance to anyone who replies.
                                          Roberto

RE: Comment on XERCESC-1780

Posted by "Sahoglu, Ozgur" <Oz...@intuit.com>.
Yes Boris, that is correct. 3.0 does not have this problem, because it's
not using Mac APIs.

I do have a Jira account and I once have submitted a bug, but after I
logged in and tried to add the comment, it gave an error, saying that I
don't have rights to comment. Oh well, maybe I did something wrong.

Thank you,


-Ozgur Sahoglu

-----Original Message-----
From: Boris Kolpackov [mailto:boris@codesynthesis.com] 
Sent: Tuesday, May 06, 2008 8:21 AM
To: c-users@xerces.apache.org
Subject: Re: Comment on XERCESC-1780

Hi Ozgur,

Sahoglu, Ozgur <Oz...@intuit.com> writes:

> Since I don't have Jira rights to comment on this bug,

If you create an account, you can comment on any bug report and
file your own:

https://issues.apache.org/jira/secure/Signup!default.jspa


> I am sending my notes to the list:

Thanks, I've added it to the bug. It is my understanding from your
comment that 3.0.0 codebase does not have this problem. Is that
correct?

Thanks,
Boris

-- 
Boris Kolpackov, Code Synthesis Tools
http://codesynthesis.com/~boris/blog
Open source XML data binding for C++:
http://codesynthesis.com/products/xsd
Mobile/embedded validating XML parsing:
http://codesynthesis.com/products/xsde


Re: Comment on XERCESC-1780

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

Sahoglu, Ozgur <Oz...@intuit.com> writes:

> Since I don't have Jira rights to comment on this bug,

If you create an account, you can comment on any bug report and
file your own:

https://issues.apache.org/jira/secure/Signup!default.jspa


> I am sending my notes to the list:

Thanks, I've added it to the bug. It is my understanding from your
comment that 3.0.0 codebase does not have this problem. Is that
correct?

Thanks,
Boris

-- 
Boris Kolpackov, Code Synthesis Tools   http://codesynthesis.com/~boris/blog
Open source XML data binding for C++:   http://codesynthesis.com/products/xsd
Mobile/embedded validating XML parsing: http://codesynthesis.com/products/xsde

Comment on XERCESC-1780

Posted by "Sahoglu, Ozgur" <Oz...@intuit.com>.
Hi guys,

Since I don't have Jira rights to comment on this bug, I am sending my
notes to the list:

I came across the same problem when running 2.8 on Leopard. The native
transcoder is causing this error. Even if you use ICU though, there is
still a problem with MacOS Posix implementation. In
/src/xercesc/util/Platforms/MacOS/MacPosixFile.cpp at line #114, the
open function calls TranscodeUniCharsToUTF8 in MacOSPlatformUtils and
this helper function uses CoreServices. 

Even though this doesn't cause any crashes, it dumps bunch of "The
process has forked and you cannot use this CoreFoundation functionality
safely. You MUST exec(). Break on
__THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTION
ALITY___YOU_MUST_EXEC__() to debug." messages on the screen. To suppress
these messages, I've used XML::transcode instead. 

In 3.0, MacOS uses pure Posix implementation. You can either merge the
PlatformUtils implementation from 3.0 to 2.8 or simply replace
TranscodeUniCharsToUTF8 call with XML::transcode in MacPosixFile.cpp. If
you're interested i can send my changes, but it's a pretty easy fix.

Cheers,


-Ozgur Sahoglu

-----Original Message-----
From: Roberto Rigamonti [mailto:roby1984@gmail.com] 
Sent: Monday, May 05, 2008 12:14 PM
To: c-users@xerces.apache.org
Subject: Re: Writing an XML Schema using Xerces and C++

It works perfectly! Thanks a lot (it's more than a week that I'm going
crazy with those problems!! :D)!!!!
                             Roberto

Alberto Massari wrote:
> You need to turn on the feature XMLUni::fgDOMWRTFormatPrettyPrint on
the
> DOMWriter object (the sample has it disabled by default, but can turn
it
> on by specifying the -wfpp=on option on the command line.
> 
> Alberto
> 
> Roberto Rigamonti wrote:
>> Hi, I've missed the CreateDOMDocument example :D
>> Merging those two samples I was able to correctly create the Schema,
>> thank you very much!! :)
>> I've also noticed that the segfaults were caused by an incorrect
>> handling of pointers due to the continuous cut&paste over samples.
>> Now only a simple question remains open for me: how can I correctly
>> format the resulting document? I mean, I found no way to correctly
>> insert newlines in the document: I've tried using the setNewLine()
>> method of DOMWriter passing "\n" and "\r\n" (even if I'm under
Linux),
>> but none of them works...
>> Thank you again for your help!
>>                               Roberto


Re: Writing an XML Schema using Xerces and C++

Posted by Roberto Rigamonti <ro...@gmail.com>.
It works perfectly! Thanks a lot (it's more than a week that I'm going
crazy with those problems!! :D)!!!!
                             Roberto

Alberto Massari wrote:
> You need to turn on the feature XMLUni::fgDOMWRTFormatPrettyPrint on the
> DOMWriter object (the sample has it disabled by default, but can turn it
> on by specifying the -wfpp=on option on the command line.
> 
> Alberto
> 
> Roberto Rigamonti wrote:
>> Hi, I've missed the CreateDOMDocument example :D
>> Merging those two samples I was able to correctly create the Schema,
>> thank you very much!! :)
>> I've also noticed that the segfaults were caused by an incorrect
>> handling of pointers due to the continuous cut&paste over samples.
>> Now only a simple question remains open for me: how can I correctly
>> format the resulting document? I mean, I found no way to correctly
>> insert newlines in the document: I've tried using the setNewLine()
>> method of DOMWriter passing "\n" and "\r\n" (even if I'm under Linux),
>> but none of them works...
>> Thank you again for your help!
>>                               Roberto

Re: Writing an XML Schema using Xerces and C++

Posted by Alberto Massari <am...@datadirect.com>.
You need to turn on the feature XMLUni::fgDOMWRTFormatPrettyPrint on the 
DOMWriter object (the sample has it disabled by default, but can turn it 
on by specifying the -wfpp=on option on the command line.

Alberto

Roberto Rigamonti wrote:
> Hi, I've missed the CreateDOMDocument example :D
> Merging those two samples I was able to correctly create the Schema,
> thank you very much!! :)
> I've also noticed that the segfaults were caused by an incorrect
> handling of pointers due to the continuous cut&paste over samples.
> Now only a simple question remains open for me: how can I correctly
> format the resulting document? I mean, I found no way to correctly
> insert newlines in the document: I've tried using the setNewLine()
> method of DOMWriter passing "\n" and "\r\n" (even if I'm under Linux),
> but none of them works...
> Thank you again for your help!
>                               Roberto
>
> Alberto Massari wrote:
>   
>> Ciao Roberto,
>> writing an XMLSchema is not different from serializing a DOM tree (e.g.
>> see the samples CreateDOMDocument + DOMPrint); could you share your code
>> so that we can spot what is going wrong?
>>
>> Alberto
>>
>> Roberto Rigamonti wrote:
>>     
>>> Hello, I'm trying to create a schema file from scratch using Xerces in
>>> C++, but the documentation in the net seems to me very obscure
>>> (excluding Doxygen-generated documentation, I haven't found much
>>> examples other than those included in the Xerces pack, and several
>>> methods are presented for writing an XML file, but none works for me
>>> because they bloat the result with DOCTYPE/other unwanted stuff).
>>> I'd like to have a result like the following one:
>>>
>>> <?xml version="1.0"?>
>>> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>>>             elementFormDefault="qualified">
>>>   <xsd:include schemaLocation="lib3DVisLine.xsd"/>
>>>   <xsd:include schemaLocation="lib3DVisPoint.xsd"/>
>>>
>>>   <xsd:element name="visor">
>>>     <xsd:complexType>
>>>       <xsd:choice minOccurs="0" maxOccurs="unbounded">
>>>       <xsd:element name="line" type="lib3DVisLine"/>
>>>       <xsd:element name="point" type="lib3DVisPoint"/>
>>>       </xsd:choice>
>>>     </xsd:complexType>
>>>   </xsd:element>
>>> </xsd:schema>
>>>
>>> I've tried many approaches, but the resulting code, even if it compiles
>>> successfully, throws a DOMException or segfaults without any good
>>> reason...
>>> Does anyone know a "good way" to create a XML Schema from scratch?
>>> Thanks in advance to anyone who replies.
>>>                                           Roberto
>>>
>>>
>>>   
>>>       
>>
>>     
>
>
>
>   



Re: Writing an XML Schema using Xerces and C++

Posted by Roberto Rigamonti <ro...@gmail.com>.
Hi, I've missed the CreateDOMDocument example :D
Merging those two samples I was able to correctly create the Schema,
thank you very much!! :)
I've also noticed that the segfaults were caused by an incorrect
handling of pointers due to the continuous cut&paste over samples.
Now only a simple question remains open for me: how can I correctly
format the resulting document? I mean, I found no way to correctly
insert newlines in the document: I've tried using the setNewLine()
method of DOMWriter passing "\n" and "\r\n" (even if I'm under Linux),
but none of them works...
Thank you again for your help!
                              Roberto

Alberto Massari wrote:
> Ciao Roberto,
> writing an XMLSchema is not different from serializing a DOM tree (e.g.
> see the samples CreateDOMDocument + DOMPrint); could you share your code
> so that we can spot what is going wrong?
> 
> Alberto
> 
> Roberto Rigamonti wrote:
>> Hello, I'm trying to create a schema file from scratch using Xerces in
>> C++, but the documentation in the net seems to me very obscure
>> (excluding Doxygen-generated documentation, I haven't found much
>> examples other than those included in the Xerces pack, and several
>> methods are presented for writing an XML file, but none works for me
>> because they bloat the result with DOCTYPE/other unwanted stuff).
>> I'd like to have a result like the following one:
>>
>> <?xml version="1.0"?>
>> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>>             elementFormDefault="qualified">
>>   <xsd:include schemaLocation="lib3DVisLine.xsd"/>
>>   <xsd:include schemaLocation="lib3DVisPoint.xsd"/>
>>
>>   <xsd:element name="visor">
>>     <xsd:complexType>
>>       <xsd:choice minOccurs="0" maxOccurs="unbounded">
>>       <xsd:element name="line" type="lib3DVisLine"/>
>>       <xsd:element name="point" type="lib3DVisPoint"/>
>>       </xsd:choice>
>>     </xsd:complexType>
>>   </xsd:element>
>> </xsd:schema>
>>
>> I've tried many approaches, but the resulting code, even if it compiles
>> successfully, throws a DOMException or segfaults without any good
>> reason...
>> Does anyone know a "good way" to create a XML Schema from scratch?
>> Thanks in advance to anyone who replies.
>>                                           Roberto
>>
>>
>>   
> 
> 
> 


Re: Writing an XML Schema using Xerces and C++

Posted by Alberto Massari <am...@datadirect.com>.
Ciao Roberto,
writing an XMLSchema is not different from serializing a DOM tree (e.g. 
see the samples CreateDOMDocument + DOMPrint); could you share your code 
so that we can spot what is going wrong?

Alberto

Roberto Rigamonti wrote:
> Hello, I'm trying to create a schema file from scratch using Xerces in
> C++, but the documentation in the net seems to me very obscure
> (excluding Doxygen-generated documentation, I haven't found much
> examples other than those included in the Xerces pack, and several
> methods are presented for writing an XML file, but none works for me
> because they bloat the result with DOCTYPE/other unwanted stuff).
> I'd like to have a result like the following one:
>
> <?xml version="1.0"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>             elementFormDefault="qualified">
>   <xsd:include schemaLocation="lib3DVisLine.xsd"/>
>   <xsd:include schemaLocation="lib3DVisPoint.xsd"/>
>
>   <xsd:element name="visor">
>     <xsd:complexType>
>       <xsd:choice minOccurs="0" maxOccurs="unbounded">
> 	  <xsd:element name="line" type="lib3DVisLine"/>
> 	  <xsd:element name="point" type="lib3DVisPoint"/>
>       </xsd:choice>
>     </xsd:complexType>
>   </xsd:element>
> </xsd:schema>
>
> I've tried many approaches, but the resulting code, even if it compiles
> successfully, throws a DOMException or segfaults without any good reason...
> Does anyone know a "good way" to create a XML Schema from scratch?
> Thanks in advance to anyone who replies.
>                                           Roberto
>
>
>