[Gambas-user] XML - Display structure

Adrien Prokopowicz adrien.prokopowicz at ...626...
Sat Aug 12 18:43:27 CEST 2017


Le Fri, 11 Aug 2017 14:25:33 +0200, Hans Lehmann <hans at ...3219...> a  
écrit:

>
> Hello,
>
> I am unable to read and display the structure of the following XML file  
> xml.xml:
> [...]
> Does anyone have an idea or suggestion or even a finished solution for  
> the above mentioned task? My projects with >XmlDocument and XmlReader do  
> not display the structure of the xml.xml file correctly. But: Other XML  
> files are displayed >correctly. We are looking for a (general) solution  
> for any XML files.
>

The problem in your code is here :

     For Each xChild In xmlElement.ChildElements
       'Extract Element-Value if the element has no children
       If (xChild.ChildElements.Count = 0) Then

You are assuming elements have either text or other elements in them, but  
your
E3 element has both.

To do this, you have to treat each element separately, and to iterate on  
all
node types using the Children property (not just Elements, which is what  
the
ChildElements property does).

The attached example gives a simple solution to your problem.

Regards,

-- 
Adrien Prokopowicz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: XmlTree-0.0.1.tar.gz
Type: application/x-gzip
Size: 11992 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20170812/c10d96b2/attachment.bin>


More information about the User mailing list