Re: loop for XML [message #89825 is a reply to message #89824] |
Sat, 06 December 2014 10:57   |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On 12/6/14, 6:17 am, skymaxwell wrote:
> Hi
>
> I need read the XML file. Here is the fragment of file
>
> <root>
> <Key1>
> <p1>13</p1>
> <tb1>10</tb1>
> </Key1>
> <KeyMeta>
> <ax>21</ax>
> <ay>59</ay>
> <az>26.7</az>
> </KeyMeta>
> </root>
>
>
> I was looking here something about XML, I find simple example with single tag
> There used these functions (oValue->GetFirstChild())->GetNodeValue())
>
>
> How build construction for multiple tags as my case ?
> I didn't find any functions in IDL help, which i could use in my case.
> May be I don't understand function Item(i).
>
> Here part of code
> ==============
> p=OBJ_NEW('IDLffXMLDOMDocument')
> p->Load,FILENAME=filenameXML
> oTopLevel=p->GetDocumentElement() ;return root IDLffXMLDOMDocument
> ; tag with name
> mainTagsList=oTopLevel->GetElementsByTagName("KeyMeta")
> ; how many KeyMeta tags in documents
> PRINT,"Length=",mainTagsList->GetLength()
> ;loop
> FOR i=0,mainTagsList->GetLength()-1 DO BEGIN
> ;How to do correct loop ???
> ENDFOR
>
> ==============
>
>
> thanks
>
Try this:
p = obj_new('IDLffXMLDOMDocument')
p->load, filename=filenameXML
oTopLevel = p->getDocumentElement() ;return root IDLffXMLDOMDocument
; tag with name
metaList = oTopLevel->getElementsByTagName('KeyMeta')
; how many KeyMeta tags in documents
metaElement = metaList->item(0)
metaChildrenList = metaElement->getElementsByTagname('*')
for c = 0L, metaChildrenList->getLength() - 1L do begin
item = metaChildrenList->item(c)
name = item->getTagname()
dataList = item->getFirstChild()
value = dataList->getNodeValue()
print, name, value, format='(%"%s = %s")'
endfor
Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Research Mathematician
Tech-X Corporation
|
|
|