× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi,

 

I am using the XML toolkit for iSeries version 4.00 to parse some documents and 
extract data.

I am using the DOM APIs to build the tree structure of the XML and then extract 
the data. However I have some problems. The attributes are not getting listed 
as nodes in the tree at all. 

 

For example I have the following XML

<catalog>

<!-- Sample -->

            <book id="101">

                        <title>Book1</title>

                        <author>Author1</author>

                        <price>1200</price>

            </book>

            <book id="102">

                        <title>Book2</title>

                        <author>Author2</author>

                        <price>2400</price>

            </book>

</catalog>

 

My understanding is that when I list the children of element Node ?book?, there 
should be a node of type 2 or Qxml_ATTR_NOD. This node should have the name 
?id? and the value ?101?. However when I build a nodelist of the children for 
this node using the QxmlDOM_Node_getChildNodes API, and then see the type for 
each node separately I do not see any nodes of type 2. Is my understanding 
wrong? Can someone help me?

 

Part of the code that I am using is as given below: (its not the full code, 
only the relevant part)

 

C                   EVAL      %str(GETTAGOPT@:256) = '*'                        
               

 * get a node list of all elements.                                             
               

C                   EVAL      DOMNODELST@ =                                     
               

C                             QxmlDOM_Document_getElementsByTagName             
               

C                               (DOMDOC@:GETTAGOPT@:Qxml_CHARSTR:20)            
               

 * get number of elements                                                       
               

C                   EVAL      WVELEMCNT = QxmlDOM_NodeList_getLength            
               

C                                            (DOMNODELST@)                      
               

C                   IF        WVELEMCNT>0                                       
               

C                   EXCEPT    HDR                                               
               

C                   EVAL      WVCNTR1=0                                         
               

C                   DOW       WVCNTR1<WVELEMCNT                                 
               

 * point to each node separately now.                                           
               

C                   EVAL      SGLNODEPTR@=QxmlDOM_NodeList_item                 
               

C                                         (DOMNODELST@:WVCNTR1)                 
               

C                   EVAL      NODETYPE=QxmlDOM_Node_getNodeType                 
               

C                                      (SGLNODEPTR@)                            
               

C                   IF        *INOV=*ON                                         
               

C                   EXCEPT    HDR                                               
               

C                   EVAL      *INOV=*OFF                                        
               

C                   ENDIF                                                       
               

C                   EXCEPT    ELEMNUM                                           
               

C                   EXCEPT    NODETYP                                           
               

 * find the element name  for this one.                                         
               

C                   EVAL      WVELEMNAM=$FINDNAME(SGLNODEPTR@)                  
               

C                   EVAL      WVELEMVAL=$NODEVAL(SGLNODEPTR@)                   
               

 * print the name and value                                                     
               

C                   IF        *INOV=*ON                                         
               

C                   EXCEPT    HDR                                               
               

C                   EVAL      *INOV=*OFF                                        
               

C                   ENDIF                                                       
               

C                   EXCEPT    NODENAME                                          
               

C                   EXCEPT    NODEVAL                                           
               

 * get a list of children                                                       
               

C                   EVAL      CHLNODELST@=QxmlDOM_Node_getChildNodes            
             

C                                         (SGLNODEPTR@)                         
             

C                   EVAL      WVNUMCHL=QxmlDOM_NodeList_getLength               
             

C                                      (CHLNODELST@)                            
             

C                   EVAL      WVCNTR2=0                                         
             

C                   DOW       WVCNTR2<WVNUMCHL                                  
             

C                   EVAL      SGLCHLPTR@=QxmlDOM_NodeList_item                  
             

C                                        (CHLNODELST@:WVCNTR2)                  
             

C                   EVAL      NODETYPE=QxmlDOM_Node_getNodeType                 
             

C                                      (SGLCHLPTR@)                             
             

C                   EVAL      WVELEMNAM=$FINDNAME(SGLCHLPTR@)                   
             

C                   EVAL      WVELEMVAL=$NODEVAL(SGLCHLPTR@)                    
             

C                   IF        *INOV=*ON                                         
             

C                   EXCEPT    HDR                                               
             

C                   EVAL      *INOV=*OFF                                        
             

C                   ENDIF                                                       
             

C                   EXCEPT    CHLDNUM                                           
             

C                   EXCEPT    CHLDTYP                                           
             

C                   EXCEPT    CHLDNAME                                          
             

C                   EXCEPT    CHLDVAL                                           
      

C                   EVAL      WVCNTR2=WVCNTR2+1                                 
      

C                   ENDDO                                                       
      

 * next element                                                                 
      

C                   EVAL      WVCNTR1=WVCNTR1+1                                 
      

 *                                                                              
      

C                   ENDDO                                                       
      

C                   ENDIF                                                       
                                                                 

 

Procedure $FINDNAME simply returns the output of QxmlDOM_Node_getNodeName and 
$NODEVAL returns the output of QxmlDOM_Node_getNodeValue.

When I check the nodetype of the children of element node ?book? there are no 
nodes of type 2 (attribute node)

 

 

- Jason


                
---------------------------------
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.