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 Drew Tennenbaum <DT...@10fold.com> on 2002/01/16 23:34:43 UTC
Parsing from a string
Can I parse an XML document that is stored in a char *? If so, does
anyone have an example of setting up the parser to do it? Currently my
application parses from a document.
Thanks,
Drew
**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the TenFold Postmaster (postmaster@10fold.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: Parsing from a string
Posted by Don Mastrovito <dm...@marathontechnologies.com>.
This ought to get you started. While this code snippet was not compiled
and tested, it was extracted from one of my projects. It demonstrates
loading from either a file or a stream.
const bool LoadFromStream = true; // Set to false for file i/o
const char *MyFileName = "C:\TEMP\TEST.XML";
const char *MyStream = "<?xml version='1.0' encoding='utf-8' ?><TAG>My
Data</TAG>";
char *BufferID = NULL;
MemBufInputSource *MemBufIS = NULL;
DOMParser *Parser = new DOMParser;
Parser->setCreateEntityReferenceNodes(false);
Parser->setDoNamespaces(false);
Parser->setDoSchema(false);
Parser->setDoValidation(false);
Parser->setToCreateXMLDeclTypeNode(true);
Parser->setValidationScheme(false);
if (!LoadFromStream)
Parser->parse(MyFileName);
else
{
MemBufIS = new MemBufInputSource(
(const XMLByte*)MyStream, // Stream pointer
::strlen(MyStream) + 1, // Byte (not character) count
&BufferID, // Buffer ID (becomes
System ID)
false); // Copy (not adopt)
caller's buffer
if (MemBufIS == NULL)
{
// Handle errors here
}
Parser->parse(*MemBufIS);
} // End if (LoadFromStream)
DOM_Node Root = Parser->getDocument();
DOM_Document Document = Parser->getDocument();
if (MemBufIS != NULL)
delete MemBufIS;
HTH,
Don
At 02:34 PM 1/16/2002 -0800, you wrote:
>Can I parse an XML document that is stored in a char *? If so, does
>anyone have an example of setting up the parser to do it? Currently my
>application parses from a document.
>
>Thanks,
>Drew
>
>
>**********************************************************************
>This email and any files transmitted with it are confidential and
>intended solely for the use of the individual or entity to whom they
>are addressed. If you have received this email in error please notify
>the TenFold Postmaster (postmaster@10fold.com).
>**********************************************************************
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org