libxml c


 
Thread Tools Search this Thread
Top Forums Programming libxml c
# 1  
Old 04-23-2007
libxml c

i have xml file like this

Code:
<root>
<sree>
<cnu value="cprogramming"\>
</sree>
</root>

to retrieve the valuse of cnu element i tried the following code
Code:
Code:
void
parseDoc() {

	xmlDocPtr doc;
	xmlNodePtr cur;

	doc = xmlParseFile("/usr/share/1.xml");
	
	if (doc == NULL ) {
		fprintf(stderr,"Document not parsed successfully. \n");
		return;
	}
	
	cur = xmlDocGetRootElement(doc);
	
	if (cur == NULL) {

		fprintf(stderr,"empty document\n");
		xmlFreeDoc(doc);
		return;
	}
	
	cur = cur->xmlChildrenNode;

	while (cur != NULL) {
		if ((!xmlStrcmp(cur->name, (const xmlChar *)"sree"))){
			parseStory (doc, cur);
		}
		 
	cur = cur->next;
	}
}
void
parseStory (xmlDocPtr doc, xmlNodePtr cur) {

	xmlChar *key;
	 cur = cur->xmlChildrenNode;

	while (cur != NULL) {
	    if ((!xmlStrcmp(cur->name, (const xmlChar *)"cnu "))) {
		    cur->name = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
		    printf("keyword: %s\n",cur->name);
		    //xmlFree();
 	    }
	cur = cur->next;
	}	
    return;
}

BUT my problem is when i print the value
iam getting null .
how can i retrieve the dataaa
thank u
sreee

Last edited by vino; 04-23-2007 at 03:05 AM.. Reason: Please put your code within the codetags.
# 2  
Old 04-27-2007
I think you want to use xmlGetProp(cur, "version") instead of xmlNodeListGetString(). I think you want to be checking for "cnu" instead of "cnu " also.
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Programming

Help in libxml++ for Linux

Hi, Using libxml++-2.6, is it possible to change the xsi:noNamespaceSchemaLocation in the root element node? e.g. from <myxml xsi:noNamespaceSchemaLocation="ABC.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> : : </myxml> to <myxml... (1 Reply)
Discussion started by: tanlccc
1 Replies

2. Shell Programming and Scripting

How to nodetype as "ELEMENT_NODE" using xml::libxml in perl?

Hi, I am using xml::libxml. Here is the code. my $parser = XML::LibXML->new(); my $xmldoc = $parser->parse_file ("file.xml") || die("Could not parse config xml file\n"); my $root = $xmldoc->getDocumentElement()|| die("Could not get Document Element \n"); $id="121313131"; # For example... (2 Replies)
Discussion started by: vanitham
2 Replies

3. Programming

[libxml++] DOmParser get node value

Hi I wrote the follow code: this->domParser = new xmlpp::DomParser(); this->domParser->set_validate(true); this->domParser->parse_file(*this->xmlFileName); this->doc = this->domParser->get_document(); xmlpp::Node* rootNode = this->doc->get_root_node(); xmlpp::Node::NodeList list =... (0 Replies)
Discussion started by: takeo.kikuta
0 Replies

4. Programming

libxml c

I've just started using libxml in c++, so far im able to parse a xml string. now i would like to replace <cms:CMSContent id="leftNav" /> with the string "left" and write the new xml out to cout; any ideas? string.xml <html xmlns:cms="http://www.test.com"> <body> <cms:CMSContent id="leftNav"... (1 Reply)
Discussion started by: spids
1 Replies
Login or Register to Ask a Question