Nima
try to recurse the DOM Tree to collect all nodes.........
Like ................
bool CXMLReaderClass::ReadFromXmlDOMReader()
{
// m_ptrXMLDoc - Collected earlier by xmlParseFile/Memory() API
// m_ptrXMLRootNode - Collected earlier by
xmlDocGetRootElement(m_ptrXMLDoc);
if ( !m_ptrXMLDoc || !m_ptrXMLRootNode)
return false;
xmlNodePtr ptrCurrXMLNode;
ptrCurrXMLNode = m_ptrXMLRootNode;
// Skip from Root Node to its 1st child node
ptrCurrXMLNode = ptrCurrXMLNode->children;
while( ptrCurrXMLNode )
{
TraverseXmlDOMReaderTree( ptrCurrXMLNode );
// Skip to next sibling
ptrCurrXMLNode = ptrCurrXMLNode->next;
}
return true;
}
void CXMLReaderClass:: TraverseXmlDOMReaderTree ( xmlNodePtr
pXMLCurrNode )
{
// Ignore TEXT Nodes as most of them are empty
if ( pXMLCurrNode->type == XML_ELEMENT_NODE )
{
// Get the node u need
// Get Attributes of the current node
}
// Traverse till the last child of the current node
pXMLCurrNode = pXMLCurrNode->children;
while ( pXMLCurrNode )
{
TraverseXmlDOMReaderTree ( pXMLCurrNode );
pXMLCurrNode = pXMLCurrNode->next;
}
}
-- Lav
________________________________
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of
Nima Tiran
Sent: Tuesday, June 10, 2008 5:11 AM
To: [email protected]
Subject: [xml] How to iterate through...
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:
This email may contain confidential or privileged information for the intended
recipient(s) and the views expressed in the same are not necessarily the views
of Zensar Technologies Ltd. If you are not the intended recipient or have
received this e-mail by error, its use is strictly prohibited, please delete
the e-mail and notify the sender. Zensar Technologies Ltd. does not accept any
liability for virus infected mails.
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
[email protected]
http://mail.gnome.org/mailman/listinfo/xml