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 Monica Lau <ml...@yahoo.com> on 2004/04/07 20:54:24 UTC

DOMWriter Questions

Hi all,

I'm trying to create a DOM document and then print
this document out as a string.  I followed the
examples from the "CreateDOMDocument" and the
"DOMPrint" code, and I have some questions below that
I hope someone can enlighten me:

1. What does this line do, especially with the "Core"
value?  
DOMImplementation *impl =
DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("Core"));

2. What does XMLString::transcode("...") do, and why
is it needed?

3. What is the advantage of creating your own XML
document using the Xerces CreateDocument API versus
just encoding the XML string manually?  I'm new to
XML, and to be honest, I don't quite see the advantage
of creating your own document.  It seems much easier
to encode the string manually.  In both cases, you
would need to know the structure of the tree.

Thanks for your time and help.

Regards,
Monica


My code snippet below:

DOMImplementation *impl =
DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("Core"));

DOMDocument *mydoc =
impl->createDocument(0,XMLString::transcode("company"),0);
DOMElement *rootElem = mydoc->getDocumentElement();
DOMElement *prodElem =
mydoc->createElement(XMLString::transcode("product"));
rootElem->appendChild(prodElem);
DOMText *prodDataVal =
mydoc->createTextNode(XMLString::transcode("Xerces-C"));
   prodElem->appendChild(prodDataVal);

DOMWriter *writer = impl->createDOMWriter();
cout <<
XMLString::transcode(writer->writeToString(*mydoc)) <<
endl;

delete writer;
mydoc->release();


__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway 
http://promotions.yahoo.com/design_giveaway/

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


Xml parsing question

Posted by lihong pei <Li...@xilinx.com>.
Hi,
I have a xml file, one of elements called "include" contains the path to another xml
file. I need to validate the merged xml file. What's the best way to handle this? (
I can't use xinclude mechanism. )
Any suggestions and code snippets?

Thanks,

Lihong


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


Re: DOMWriter Questions

Posted by Monica Lau <ml...@yahoo.com>.
Hi all,
 
Thanks for all your responses.  In the following code snippet (taken from DOMCreation and from DOMPrint), I just want to make sure that I've deleted all the memory approriately.  Does the "getDOMImplementation()" function allocate memory on the heap?  (I've looked at the online documentation, but couldn't find much about this.)  
 
Thanks again for your time and help.
 
Regards,
Monica
 
 
DOMImplementation *impl =
DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("Core"));

DOMDocument *mydoc =
impl->createDocument(0,XMLString::transcode("company"),0);
DOMElement *rootElem = mydoc->getDocumentElement();
DOMElement *prodElem =
mydoc->createElement(XMLString::transcode("product"));
rootElem->appendChild(prodElem);
DOMText *prodDataVal =
mydoc->createTextNode(XMLString::transcode("Xerces-C"));
   prodElem->appendChild(prodDataVal);

DOMWriter *writer = impl->createDOMWriter();
cout <<
XMLString::transcode(writer->writeToString(*mydoc)) <<
endl;

// Delete Memory
writer->release();
mydoc->release();
delete impl;




---------------------------------
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway - Enter today

Re: DOMWriter Questions

Posted by Gareth Reakes <pa...@parthenoncomputing.com>.
> I'm new to the Xerces parser, so I was just wondering
> what other methods the DOM supports and would I want
> to perform on the XML string?

Take a look at a tutorial or the docs for a full list.

> So far, I've simply
> taken the XML string and performed schema validation
> and parsing on it.  So, I haven't manipulated it.  If
> this is the case, isn't it simpler to encode the
> string manually?

In general no. It is surprisingly difficult to write code that always
outputs well formed XML when you are dealing with strings. There are all
sorts of escaping issues etc. In addition, you cannot use C++ string if
you want foreign language support.

Gareth


-- 
Gareth Reakes, Managing Director            +44-1865-811184
Parthenon Computing                http://www.parthcomp.com




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


Re: DOMWriter Questions

Posted by Monica Lau <ml...@yahoo.com>.
Hi,

> > 3. What is the advantage of creating your own XML
> > document using the Xerces CreateDocument API
> versus
> > just encoding the XML string manually?  I'm new to
> > XML, and to be honest, I don't quite see the
> advantage
> > of creating your own document.  It seems much
> easier
> > to encode the string manually.  In both cases, you
> > would need to know the structure of the tree.
> 
> If I follow you correctly here then I think you are
> suggesting just
> building a string up that is XML. If this is the
> case then you would not
> be able to call any of the methods that DOm supports
> on this string. It
> would be hard to ensure the XML is well formed and
> very hard to manipulate
> it.

I'm new to the Xerces parser, so I was just wondering
what other methods the DOM supports and would I want
to perform on the XML string?  So far, I've simply
taken the XML string and performed schema validation
and parsing on it.  So, I haven't manipulated it.  If
this is the case, isn't it simpler to encode the
string manually?

Thanks for your help and quick response.

Monica


__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway 
http://promotions.yahoo.com/design_giveaway/

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


Re: DOMWriter Questions

Posted by Gareth Reakes <pa...@parthenoncomputing.com>.
Hi,

> DOMImplementation *impl =
> DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("Core"));

It specifies a specific implementation to use. For example Core or
Load/Save. Take a look at the specs a tutorial or the docs for more info

http://xml.apache.org/xerces-c/apiDocs/classDOMImplementationRegistry.html

>
> 2. What does XMLString::transcode("...") do, and why
> is it needed?

It converts from a string to the internal xerces format which supports
UTF16. Again, take a look at the docs for more info

http://xml.apache.org/xerces-c/apiDocs/classXMLString.html#z985_14


> 3. What is the advantage of creating your own XML
> document using the Xerces CreateDocument API versus
> just encoding the XML string manually?  I'm new to
> XML, and to be honest, I don't quite see the advantage
> of creating your own document.  It seems much easier
> to encode the string manually.  In both cases, you
> would need to know the structure of the tree.

If I follow you correctly here then I think you are suggesting just
building a string up that is XML. If this is the case then you would not
be able to call any of the methods that DOm supports on this string. It
would be hard to ensure the XML is well formed and very hard to manipulate
it.


Gareth

-- 
Gareth Reakes, Managing Director            +44-1865-811184
Parthenon Computing                http://www.parthcomp.com




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