Hi,
In the heading the SYSTEM part, on the left of DOCTYPE, doesn�t appear in my output
XML file. Can you tell me why!
The Code:
int main(int argC, char* argV[])
{
// Initialize the XML4C2 system.
try
{
XMLPlatformUtils::Initialize();
}
catch(const XMLException& toCatch)
{
char *pMsg = XMLString::transcode(toCatch.getMessage());
cerr << "Error during Xerces-c Initialization.\n"
<< " Exception message:"
<< pMsg;
delete [] pMsg;
return 1;
}
// Watch for special case help request
if (argC > 1)
{
cout << "\nUsage:\n"
" CreateDOMDocument\n\n"
"This program creates a new DOM document from scratch in memory.\n"
"It then prints the count of elements in the tree.\n"
<< endl;
XMLPlatformUtils::Terminate();
return 1;
}
{
// Nest entire test in an inner block.
// The tree we create below is the same that the XercesDOMParser would
// have created, except that no whitespace text nodes would be created.
// <company>
// <product>Xerces-C</product>
// <category idea='great'>XML Parsing Tools</category>
// <developedBy>Apache Software Foundation</developedBy>
// </company>
DOMImplementation* impl =
DOMImplementationRegistry::getDOMImplementation(X("Core"));
DOMDocumentType* type =
impl->createDocumentType(X("company"),X(""),X("exp.dtd"));
DOMDocument* doc = impl->createDocument(
0, // root element namespace URI.
X("company"), // root element name
DOMElement* rootElem = doc->getDocumentElement();
DOMElement* prodElem = doc->createElement(X("product"));
rootElem->appendChild(prodElem);
DOMText* prodDataVal = doc->createTextNode(X("Xerces-C"));
prodElem->appendChild(prodDataVal);
DOMElement* catElem = doc->createElement(X("category"));
rootElem->appendChild(catElem);
catElem->setAttribute(X("idea"), X("great"));
DOMText* catDataVal = doc->createTextNode(X("XML Parsing Tools"));
catElem->appendChild(catDataVal);
DOMElement* devByElem = doc->createElement(X("developedBy"));
rootElem->appendChild(devByElem);
DOMText* devByDataVal = doc->createTextNode(X("Apache Software
Foundation"));
devByElem->appendChild(devByDataVal);
//DOMWriter* theSerializer = ((DOMImplementationLS*)impl)->createDOMWriter();
XMLFormatTarget *myFormTarget = new LocalFileFormatTarget("exp.xml");
((DOMImplementationLS*)impl)->createDOMWriter()->writeNode(myFormTarget, *doc);
//
// Now count the number of elements in the above DOM tree.
//
unsigned int elementCount = doc->getElementsByTagName(X("*"))->getLength();
cout << "The tree just created contains: " << elementCount
<< " elements." << endl;
doc->release();
}
XMLPlatformUtils::Terminate();
return 0;
}
-----Original Message-----
From: Gareth Reakes [mailto:[EMAIL PROTECTED]]
Sent: segunda-feira, 7 de Outubro de 2002 11:45
To: [EMAIL PROTECTED]
Subject: Re: DOM Writer
Hi,
I added the type to the creation of the document in the sample
CreateDOMDocument and wrote it to the file before the counting part. This
produced the XML you were expecting. Have a go at that and if it does not
work then post your code.
Gareth
On Mon, 7 Oct 2002, Paulo David Oliveira wrote:
>
> Hello,
>
> I'm writing a DOMDocument in memory with DOMWriter and then calling writeNode to a
>file. In the xml file just created the dtd file does not appear, in other words
>"SYSTEM "exp.dtd" is missing. The document type is created like this:
>
> DOMDocumentType* type =
>impl->createDocumentType(X("company"),X(""),X("exp.dtd"));
>
> DOMDocument* doc = impl->createDocument(
> 0, // root element namespace URI.
> X("company"), // root element name
> type);
>
>
> The final XML:
>
> <?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
>
> <!DOCTYPE company>
>
> <company><product>Xerces-C</product><category name="0">XML Parsing
>Tools</category><category name="Paulo"
>name1="Oliveira">Experiencia<Qualquer>Nome</Qualquer></category><category
>name="2">XML Parsing Tools</category><category name="3">XML Parsing
>Tools</category><category name="4">XML Parsing Tools</category><developedBy>Apache
>Software Foundation</developedBy></company>
>
> The final XML expected:
>
> <?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
>
> <!DOCTYPE company SYSTEM "exp.dtd">
>
> <company><product>Xerces-C</product><category name="0">XML Parsing
>Tools</category><category name="Paulo"
>name1="Oliveira">Experiencia<Qualquer>Nome</Qualquer></category><category
>name="2">XML Parsing Tools</category><category name="3">XML Parsing
>Tools</category><category name="4">XML Parsing Tools</category><developedBy>Apache
>Software Foundation</developedBy></company>
>
>
> What is missing?
>
>
>
> Thank you!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
Gareth Reakes, Head of Product Development
DecisionSoft Ltd. http://www.decisionsoft.com
Office: +44 (0) 1865 203192
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]