You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Gennady Khokhorin <go...@aerometric-ak.com> on 2007/12/08 03:19:41 UTC

newbie question: how to insert XSD

Hello, all.
I was trying to create a template from scratch.
Can not insert <?xml-stylesheet tag before the root element, its appear
at the end of xml after root element closing tag. Code is like that:
 
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* doc = impl->createDocument(
                           NULL,			// root element
namespace URI.
                           _T("metadata"),	// root element name
                           NULL);			// document type
object (DTD).
DOMProcessingInstruction* procInstruction =
doc->createProcessingInstruction(_T("xml-stylesheet"),
_T("type=\"text/xsl\" href=\"my.xsl\""));	
doc->appendChild(procInstruction);

Hope it is not a bug. 

Also, what command can insert XSD location in the root element like
that:
<metadata xmlns="..." xmlns:xsi="..." xsi:schemaLocation="my.xsd">

Waiting for any help.

Thank you.
gok

---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


Re: newbie question: how to insert XSD

Posted by David Bertoni <db...@apache.org>.
Gennady Khokhorin wrote:
> Hello, all.
> I was trying to create a template from scratch.
> Can not insert <?xml-stylesheet tag before the root element, its appear
> at the end of xml after root element closing tag. Code is like that:
>  
> XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* doc = impl->createDocument(
>                            NULL,			// root element
> namespace URI.
>                            _T("metadata"),	// root element name
>                            NULL);			// document type
> object (DTD).
> DOMProcessingInstruction* procInstruction =
> doc->createProcessingInstruction(_T("xml-stylesheet"),
> _T("type=\"text/xsl\" href=\"my.xsl\""));	
> doc->appendChild(procInstruction);
> 
> Hope it is not a bug. 
No, it's not a bug.  Creating the document also creates the document 
element, and then you "append" a child processing instruction node.  You 
need to use DOMNode::insertBefore() to insert before an existing child.

> 
> Also, what command can insert XSD location in the root element like
> that:
> <metadata xmlns="..." xmlns:xsi="..." xsi:schemaLocation="my.xsd">
You need to add the appropriate attributes to the document element.  See 
DOMElement::setAttributeNS() for more information.

Please consider reading a tutorial on the DOM before posting generic 
questions.  A good tutorial will answer many of your questions, and save 
lots of bandwidth on the list.

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org