|
With XML4PR500 you can code this (only relevant part):
DBookNum S 10I 0
DCatalog DS qualified
D ID 10A
DomDoc = QxmlXercesDOMParser_getDocument(DomParse);
// get number of books
BookNum = getElemCount('catalog/book':*Omit);
// for each book
for i = 1 to BookNum;
Node = getNode('catalog/book':i-1);
Catalog.Id = getAttr(Node:'id');
endfor;
===========
In a service program or inline the main you build your procedures
getElementCount
returns the count of <book> using
NodeList = QxmlDOMDocument_getElementsByTagName
(DomDoc:ntString:Qxml_CHARSTR:0);
ChildNode = QxmlDOMNodeList_item(NodeList:0);
QxmlDOMNodeList_getLength(NodeList);
getNode
is similar to getElementCount but returns ChildNode
getAttr
returns the attribute of n <book> using
AttrNode = QxmlDOMElement_getAttribute
(Node:ntString:Qxml_CHARSTR:0);
QxmlDOMDocument_getElementsByTagName
, getNode and getAttr are procedures
----- Original Message -----
From: "Jason Botwinick" <jasonbotwinick@xxxxxxxxx>
To: <rpg400-l@xxxxxxxxxxxx>
Sent: Wednesday, August 11, 2004 3:30 PM
Subject: Question on XML parsing
>
> 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!
> --
> This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
> To post a message email: RPG400-L@xxxxxxxxxxxx
> To subscribe, unsubscribe, or change list options,
> visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
> or email: RPG400-L-request@xxxxxxxxxxxx
> Before posting, please take a moment to review the archives
> at http://archive.midrange.com/rpg400-l.
>
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.