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 Florent Bouchy <fl...@gmail.com> on 2005/09/14 13:56:07 UTC

Problems using XMLSchema & XSI with Xerces-C

Hi all,
I've already posted questions here but they've never been answered...I
hope this one will be !

My problem is that I don't manage to write a DOMDocument in a XML file
like I want to : I use a XMLSchema grammar and I can't find out how to
specify it !
Here is the header I want to write :
---
<?xml version="1.0" encoding="utf-8" ?>
<dataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="XMLSchema.xsd">
---
And here is the only thing I'm able to write with Xerces :
---
<?xml version="1.0" encoding="utf-8" standalone="no" ?><dataset
xmlns="http://www.w3.org/2001/XMLSchema-instance">
---

This is the code I'm using to do this :
---
LocalFileFormatTarget* sortie = new LocalFileFormatTarget(fichier.c_str());
	
DOMImplementation* impl =
DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("LS"));

DOMWriter* writer = ((DOMImplementationLS*)impl)->createDOMWriter();

DOMDocument* doc = impl->createDocument(
		XMLString::transcode("http://www.w3.org/2001/XMLSchema-instance"),
		XMLString::transcode("dataset"),
		NULL);

doc->setStandalone(false);
doc->setVersion(XMLString::transcode("1.0"));
doc->setEncoding(XMLString::transcode("utf-8"));

// I'll fill in the document here, but later

writer->writeNode(sortie, *doc);  
---

What should I do ? Should I use XMLSchemaDescription[Impl] ? If yes, how ??

Thanks for any help.


Florent

Re: Problems using XMLSchema & XSI with Xerces-C

Posted by Florent Bouchy <fl...@gmail.com>.
Thanks a lot !!! This was exactly what I was looking for.

About calling XMLString::release : the "auto"-allocated string/XMLCh
variables aren't freed when their owning function exits ? If not, you
mean I should name every string/XMLCh and release them after ?


Now I have little questions :
- how to make a new line between the <? ... ?> and <root element ...> tags ?
- how to avoid printing the "standalone" attribute ?


Florent


On 9/14/05, Alberto Massari <am...@datadirect.com> wrote:
> Hi Florent,
> 
> At 13.56 14/09/2005 +0200, Florent Bouchy wrote:
> >Hi all,
> >I've already posted questions here but they've never been answered...I
> >hope this one will be !
> >
> >My problem is that I don't manage to write a DOMDocument in a XML file
> >like I want to : I use a XMLSchema grammar and I can't find out how to
> >specify it !
> >Here is the header I want to write :
> >---
> ><?xml version="1.0" encoding="utf-8" ?>
> ><dataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> >xsi:noNamespaceSchemaLocation="XMLSchema.xsd">
> >---
> >And here is the only thing I'm able to write with Xerces :
> >---
> ><?xml version="1.0" encoding="utf-8" standalone="no" ?><dataset
> >xmlns="http://www.w3.org/2001/XMLSchema-instance">
> >---
> >
> >This is the code I'm using to do this :
> >---
> >LocalFileFormatTarget* sortie = new LocalFileFormatTarget(fichier.c_str());
> >
> >DOMImplementation* impl =
> >DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("LS"));
> >
> >DOMWriter* writer = ((DOMImplementationLS*)impl)->createDOMWriter();
> >
> >DOMDocument* doc = impl->createDocument(
> >
> >XMLString::transcode("http://www.w3.org/2001/XMLSchema-instance"),
> >                 XMLString::transcode("dataset"),
> >                 NULL);
> 
> DOMDocument* doc = impl->createDocument(
>                  NULL,
>                  XMLString::transcode("dataset"),
>                  NULL);
> doc->getDocumentElement()->setAttributeNS(
>                 XMLString::transcode("http://www.w3.org/2001/XMLSchema-instance"),
>                 XMLString::transcode("xsi:noNamespaceSchemaLocation"),
>                 XMLString::transcode("XMLSchema.xsd"));
> 
> Also, keep in mind that the memory returned by XMLString::transcode
> should be released by calling XMLString::release, or you will have a
> memory leak.
> 
> Alberto
> 
> >doc->setStandalone(false);
> >doc->setVersion(XMLString::transcode("1.0"));
> >doc->setEncoding(XMLString::transcode("utf-8"));
> >
> >// I'll fill in the document here, but later
> >
> >writer->writeNode(sortie, *doc);
> >---
> >
> >What should I do ? Should I use XMLSchemaDescription[Impl] ? If yes, how ??
> >
> >Thanks for any help.
> >
> >
> >Florent
> 
> 
>

Re: Problems using XMLSchema & XSI with Xerces-C

Posted by Alberto Massari <am...@datadirect.com>.
Hi Florent,

At 13.56 14/09/2005 +0200, Florent Bouchy wrote:
>Hi all,
>I've already posted questions here but they've never been answered...I
>hope this one will be !
>
>My problem is that I don't manage to write a DOMDocument in a XML file
>like I want to : I use a XMLSchema grammar and I can't find out how to
>specify it !
>Here is the header I want to write :
>---
><?xml version="1.0" encoding="utf-8" ?>
><dataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>xsi:noNamespaceSchemaLocation="XMLSchema.xsd">
>---
>And here is the only thing I'm able to write with Xerces :
>---
><?xml version="1.0" encoding="utf-8" standalone="no" ?><dataset
>xmlns="http://www.w3.org/2001/XMLSchema-instance">
>---
>
>This is the code I'm using to do this :
>---
>LocalFileFormatTarget* sortie = new LocalFileFormatTarget(fichier.c_str());
>
>DOMImplementation* impl =
>DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("LS"));
>
>DOMWriter* writer = ((DOMImplementationLS*)impl)->createDOMWriter();
>
>DOMDocument* doc = impl->createDocument(
> 
>XMLString::transcode("http://www.w3.org/2001/XMLSchema-instance"),
>                 XMLString::transcode("dataset"),
>                 NULL);

DOMDocument* doc = impl->createDocument(
                 NULL,
                 XMLString::transcode("dataset"),
                 NULL);
doc->getDocumentElement()->setAttributeNS(
                XMLString::transcode("http://www.w3.org/2001/XMLSchema-instance"),
                XMLString::transcode("xsi:noNamespaceSchemaLocation"),
                XMLString::transcode("XMLSchema.xsd"));

Also, keep in mind that the memory returned by XMLString::transcode 
should be released by calling XMLString::release, or you will have a 
memory leak.

Alberto

>doc->setStandalone(false);
>doc->setVersion(XMLString::transcode("1.0"));
>doc->setEncoding(XMLString::transcode("utf-8"));
>
>// I'll fill in the document here, but later
>
>writer->writeNode(sortie, *doc);
>---
>
>What should I do ? Should I use XMLSchemaDescription[Impl] ? If yes, how ??
>
>Thanks for any help.
>
>
>Florent