[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[xml] trying to build xml from dtd. please look at my code, thanks



/*
This method takes the root node and builds a tree from it,
storing the resulting string in the xmlString parameter
*/

char* getNodes(xmlNode* dtdNode, char* xmlString) {	

	xmlElementContentPtr dtdFirstContentElement;	
	xmlElementPtr dtdElement;
	xmlAttributePtr dtdAttribute;

	xmlNode *NodeChildren, *xnode;

	char *nodeName;
	char *attrName;
	char *xmlS;
	//char *rootName;
	
	xmlS = calloc(100,sizeof(char));
	nodeName = calloc(100,sizeof(char));
	attrName = calloc(100,sizeof(char));
	//rootName = calloc(100,sizeof(char));

	if(dtdNode==NULL)	{
		return xmlString;
	}
	
	//xmlString = nodeName = attrName = ""; 		

	
	/* get the root of the DTD document */	
	//dtdNode = dtd->children;

		
	
		
	if (dtdNode->type == XML_ELEMENT_DECL){     
		/*This node is: ELEMENT DECLARATION*/
		
		dtdElement = (xmlElement*)dtdNode;

		strcpy(nodeName,dtdNode->name);
				
		//Look for its content

		strcat(xmlString,"<");
		strcat(xmlString,nodeName);	
					

		//Look for each Attributes
		dtdAttribute = dtdElement->attributes;
		
		while (dtdAttribute != NULL) {				
			strcpy(attrName,dtdAttribute->name);

			strcat(xmlString," ");
			strcat(xmlString,attrName);
			strcat(xmlString,"=\"\"");				
			dtdAttribute = dtdAttribute->next;
		}
		strcat(xmlString,">\n");
		
		
		printf("%s",(char*)dtdFirstContentElement->name);

		NodeChildren = dtdNode->children;
		

		//recursively get the children node b4 moving on
		xmlS = getNodes(NodeChildren,"");
		strcat(xmlString,xmlS);		
						
		strcat(xmlString,"</");
		strcat(xmlString,nodeName);
		strcat(xmlString,">\n");	

		if (dtdNode->type == XML_ATTRIBUTE_DECL){
			fprintf(stdout,"%s: Attribute Declaration!\n",dtdNode->name);
			fprintf(stdout,"Default: %d\n", ((xmlAttributePtr)dtdNode)->def);
		}	
		dtdNode = dtdNode->next;// now move to the next node...
		return getNodes(dtdNode,xmlString);		
		
	}			
}
-- 
__________________________________________________________
Sign-up for your own FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup

Save up to $160 by signing up for NetZero Platinum Internet service.
http://www.netzero.net/?refcd=N2P0602NEP8




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]