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 Williams Roger <RW...@OLDMUTUAL.com> on 2001/03/14 11:07:30 UTC

FW: NEWBIE: trying to retrieve node value from xml string in mem

I have two problems

First: When I try to execute the parse member function by passing it a
memory buffer, The DOM_Node I get is NULL. But when I pass it a file with
the exact same contects of the memory buffer. I get a Node.

Second: When I do get a DOM_Node that is not null, I cannot get the value of
the element. by using the member function getNodeValue. However, I do get
the  Node Name by using the member function getNodeName, which is
successfull.

I am new to XML , and i am trying to check randomly(not sequentially) if a
particular tag exists, and if it exist, to extract its value. And I want to
do this by parsing not from a file , but from memory(ie, I am getting a
char* as input).

Can anybody assist/help me

here is what I tried(win32 console app):

#include <stdlib.h>
#include <string.h>
#include <iostream.h>
#include <stdio.h>
#include <afx.h>
#include <parsers/SAXParser.hpp>
#include <framework/MemBufInputSource.hpp>
#include <util/PlatformUtils.hpp> 
#include <parsers/DOMParser.hpp> 
#include <dom/DOM_NodeList.hpp>
#include <dom/DOM_Node.hpp> 

int main() {
	char*  gXMLInMemBuf =
	"<locprop>\n\tlocation property
1\n\b</locprop>\n<updprop>\n\t\bupdate property\n\b</updprop>\n";

/*"<locprop>\n\
	location property 1\n\
</locprop>\n\
<updprop>\n\
	update property\n\
</updprop>\n\
";
*/	printf("\n%s\n",gXMLInMemBuf);	
static const char*  gMemBufId = "prodInfo";

	try
    {
         XMLPlatformUtils::Initialize();
    }
    catch (const XMLException& toCatch)
    {
         cerr << "Error during initialization! Message:\n"
		
              << /*StrX*/(toCatch.getMessage()) << endl;
         return 1;
    }

	//MemBufInputSource* memBufIS;
	const XMLByte* pXmlByte=NULL;
	pXmlByte = (const XMLByte*) gXMLInMemBuf;
	MemBufInputSource * memBufIS;
	try {
		
		memBufIS = new MemBufInputSource
		(
			(const XMLByte*)gXMLInMemBuf
			, sizeof(gXMLInMemBuf)
			, gMemBufId
			, false
		);
	}	
	catch (const XMLException& pE) {
		printf("\nexcpetion\n");
	}

	/*DOMParser parser;
	parser.parse(*memBufIS);
	DOM_Document DomDoc = parser.getDocument();
	DOM_NodeList List;
	List = DomDoc.getElementsByTagName("*");
	int n=0;
	DOM_Node Node = List.item(n);
	if (Node==NULL) 
		return 0;
	DOMString dstrVal = Node.getNodeValue();
	
	char* strVal=dstrVal.transcode();
	cout<<"\nVal:\t"<<strVal<<"\n";
	//parser.~DOMParser;
	*/
	try {
		DOMParser *pParser=NULL;
		pParser = new DOMParser;
		//pParser->parse(*memBufIS);
		pParser->parse("c:/myxml.xml");
		DOM_Document *pDomDoc=NULL;
		pDomDoc = new DOM_Document(pParser->getDocument());
		DOM_NodeList *pNodeList=NULL;
		pNodeList = new
DOM_NodeList(pDomDoc->getElementsByTagName("*")); 
		//DOM_Node *pNode=NULL;
		//pNode = new DOM_Node(pNodeList->item(0));
		DOM_Node Node = pNodeList->item(0);
		if(Node==NULL)
			return 0;
		unsigned int ln = 0;
		ln = pNodeList->getLength();
		short NodeType = 0;
		NodeType = Node.getNodeType();
		DOMString dsVal=Node.getNodeName(); //when replacing
getNodeName with getNodevalue, dsVal is NULL
		char *szVal = dsVal.transcode();
		cout<<"\n"<<szVal<<"\n";
	}
	catch(XMLException *pE) {
		pE->getMessage();
	}
	
	//I also further catches here for the Dom classes

	return 0;
}
 

-----Original Message-----
From: xerces-c-dev-help@xml.apache.org
[mailto:xerces-c-dev-help@xml.apache.org]
Sent: 14 March 2001 10:27 AM
To: RWilliams2@OLDMUTUAL.com
Subject: confirm subscribe to xerces-c-dev@xml.apache.org


Hi! This is the ezmlm program. I'm managing the
xerces-c-dev@xml.apache.org mailing list.

To confirm that you would like

   RWilliams2@OLDMUTUAL.com

added to the xerces-c-dev mailing list, please send
an empty reply to this address:

 
xerces-c-dev-sc.984558409.cmacinhjiiooonpbbdoa-RWilliams2=OLDMUTUAL.com@xml.
apache.org

Usually, this happens when you just hit the "reply" button.
If this does not work, simply copy the address and paste it into
the "To:" field of a new message.

This confirmation serves two purposes. First, it verifies that I am able
to get mail through to you. Second, it protects you in case someone
forges a subscription request in your name.

Some mail programs are broken and cannot handle long addresses. If you
cannot reply to this request, instead send a message to
<xe...@xml.apache.org> and put the
entire address listed above into the "Subject:" line.


--- Administrative commands for the xerces-c-dev list ---

I can handle administrative requests automatically. Please
do not send them to the list address! Instead, send
your message to the correct command address:

To subscribe to the list, send a message to:
   <xe...@xml.apache.org>

To remove your address from the list, send a message to:
   <xe...@xml.apache.org>

Send mail to the following for info and FAQ for this list:
   <xe...@xml.apache.org>
   <xe...@xml.apache.org>

Similar addresses exist for the digest list:
   <xe...@xml.apache.org>
   <xe...@xml.apache.org>

To get messages 123 through 145 (a maximum of 100 per request), mail:
   <xe...@xml.apache.org>

To get an index with subject and author for messages 123-456 , mail:
   <xe...@xml.apache.org>

They are always returned as sets of 100, max 2000 per request,
so you'll actually get 100-499.

To receive all messages with the same subject as message 12345,
send an empty message to:
   <xe...@xml.apache.org>

The messages do not really need to be empty, but I will ignore
their content. Only the ADDRESS you send to is important.

You can start a subscription for an alternate address,
for example "john@host.domain", just add a hyphen and your
address (with '=' instead of '@') after the command word:
<xe...@xml.apache.org>

To stop subscription for this address, mail:
<xe...@xml.apache.org>

In both cases, I'll send a confirmation message to that address. When
you receive it, simply reply to it to complete your subscription.

If despite following these instructions, you do not get the
desired results, please contact my owner at
xerces-c-dev-owner@xml.apache.org. Please be patient, my owner is a
lot slower than I am ;-)

--- Enclosed is a copy of the request I received.

Return-Path: <RW...@OLDMUTUAL.com>
Received: (qmail 53325 invoked from network); 14 Mar 2001 08:26:47 -0000
Received: from mail1.is.co.za (196.36.153.34)
  by h31.sny.collab.net with SMTP; 14 Mar 2001 08:26:47 -0000
Received: from za-om-virus1 ([160.123.100.70])
	by mail1.is.co.za (8.9.3/8.9.3) with SMTP id KAA04833
	for <xe...@xml.apache.org>; Wed, 14 Mar 2001
10:26:44 +0200
Received: FROM omrxch002.intranet BY za-om-virus1 ; Wed Mar 14 10:23:02 2001
+0200
Received: by OMRXCH002 with Internet Mail Service (5.5.2653.19)
	id <G75T6N6K>; Wed, 14 Mar 2001 10:26:44 +0200
Message-ID: <8B...@OMRXCH012>
From: Williams Roger <RW...@OLDMUTUAL.com>
To: "'xerces-c-dev-subscribe@xml.apache.org'"
	 <xe...@xml.apache.org>
Subject: 
Date: Wed, 14 Mar 2001 10:24:49 +0200
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2653.19)
Content-Type: text/plain;
	charset="iso-8859-1"
X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N

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