Nima , Suppose u have to collect values of all properties ( prop_x ) in line <element_x prop_1="value1" prop_2="val2"
prop_3="val_3" > Then 1st traverse using DOM Tree , until u encounter a node
with xmlNodePtr->name as same as element_x ( Take the help of
xmlStrcmp() API ) . Say this node is xmlNodePtr pXmlNodeElemX To collect / print all Atrribute /Property Nodes of element_x use………….. if (pXmlNodeElemX->properties ) { // Traverse
all Attribs of a current XML Node xmlAttrPtr pXMLCurrAttrib; for (pXMLCurrAttrib = pXmlNodeElemX->properties; pXMLCurrAttrib; pXMLCurrAttrib
= pXMLCurrAttrib ->next) { printf("\n\nAttribute
Name = %s" , pXMLCurrAttrib ->name); xmlChar*
pszAttrContent =
xmlNodeListGetString(m_ptrXMLDoc,pXMLCurrAttrib->children,1); printf("\nAttribute
Content = %s\n" , pszAttrContent); if
(pszAttrContent) xmlFree(pszAttrContent);
} } Alternatively if u want only value of a particular attribute / property
of Node <element_x>
say only prop_2 Use…….. xmlChar* pszAttrContent = xmlGetProp(pXmlNodeElemX,(const xmlChar*)” prop_2”); if (pszAttrContent) xmlFree(pszAttrContent); -------- Lav From:
xml-bounces gnome org [mailto:xml-bounces gnome org] On Behalf Of Nima Tiran I brought a piece of XML
file that I'm trying to parse it and somehow I stuck to find a way to iterate
through them and collect the properties in each line(element)
I tried to use print_element_names() function in sample code but had no success. I can get the 'element_x' and their properties in first line below but from that point don't know how to iterate to its nested element(section_1) and further and collect them all.
Any help greatly appreciated,
Thanks, Nima
<element_x prop_1="value1" prop_2="val2"
prop_3="val_3" > <section_1> <elem_1
category="<CompanyName>"
qualifier="Is">company1</elem_1 > <elem_2>doc1.pic</elem_2 > < elem_1 category="<CompanyName>"
qualifier="Is">Company2.</elem_1 > < elem_2 >doc2.pic</elem_2 > < elem_1 category="<CompanyName>"
qualifier="Is">Company3</elem_1 > < elem_2 >doc1.pic</elem_2 > < elem_2 >doc3.pic</elem_2 > </section_1> </element_x > DISCLAIMER: |