Click here to Skip to main content
15,894,740 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everyone.

I have a little problem to read a xml file, first I download a xml file from a webservice, the xml is very dinamics


this is little example
XML
<Table>
<Product ID="1">
<Product_id>1</Product_id>
<Product_name>Product 1</Product_name>
<Product_price/>
</Product>
<Product ID="2">
<Product_id>2</Product_id>
<Product_name>Product 2</Product_name>
<Product_price>2000</Product_price>
<Description>
    <Date>25-10-2015</Date></Description>
    <Quantity>45</Quantity>
</Product>
<Product ID="3">
<Product_id>3</Product_id>
<Product_name>Product 3</Product_name>
<Product_price>3000</Product_price>
</Product>
<Product ID="4">
<Product_id>4</Product_id>
<Product_name>Product 4</Product_name>
<Product_price>4000</Product_price>
</Product>
</Table>



In the element "Description" has element inside, my question is I can know if that said element is an element which brings together other elements inside.

I'm trying to make it on visual basic.

Please if someone knows let me know it.

Thanks.
Posted
Updated 25-Jul-15 17:32pm
v3

XML
<Description>
    <Date>25-10-2015</Description>

First of all your Date tag is malformed the end tag is missing.

Question is obvious. you know that an element have children because the next tag is not the closing tag of the element.

After you read <product> tag, every tag that is not </product> is a children element.
 
Share this answer
 
v2
Forget the element Date, is part of example.
The logic is show the element Description have more line inside.
 
Share this answer
 
Comments
Patrice T 25-Jul-15 23:31pm    
Solutions are only to answer the first question.
When want to say something about a solution, use 'Have a Question or Comment' or 'Reply' to comment a comment.
Salomon Pineda Silva 27-Jul-15 21:07pm    
sorry, I could not reply your post
Here are the examples, in the first code you can see the fourth LineasFactSinOc not have child nodes.

XML
<ICDoc version="4.01">
<FechaXML>2014-10-15T12:00:09</FechaXML>
<Documento ID="6549657">
<LineasFactSinOc/>
<Encabezado>
<IdDoc>
<TipoDoc>FC</TipoDoc>
<NumDoc>1020065</NumDoc>
<FolioUnico>0101-382411</FolioUnico>
<FchTransaccion>2014-05-30T18:53:26</FchTransaccion>
<FchEmis>2014-05-14</FchEmis>
<FchVenc>2014-06-13</FchVenc>
<FchRecepcion>2014-05-19</FchRecepcion>
<FchEstimadaPago>2014-06-06</FchEstimadaPago>
<Comentarios>Nombre Usuario:MVENEGASN Numero Lote:138621</Comentarios>
<TipoDocTributario>Exenta</TipoDocTributario>
<AgenteRetenedor>1</AgenteRetenedor>
<SinOC>false</SinOC>
<Electronico>false</Electronico>
<Estado>...</Estado>
<EstadoAsoc>...</EstadoAsoc>
<MonedaRef>...</MonedaRef>
<TipoDocFactura>...</TipoDocFactura>
</IdDoc>
<Comprador>...</Comprador>
<Proveedor>...</Proveedor>
<Totales>...</Totales>
</Encabezado>
<DocAsociados ID="9475465">...</DocAsociados>
<Cuadre ID="1283873">...</Cuadre>
</Documento>
</ICDoc>


But on this part it have. child node and this both code belong to the same xml file downloaded.

If you see too there is more node null

My question is for example. the node "LineasFactSinOc" how can check if have more node inside and if is null or not.

if I not get wrong there is more nodes nulls.

XML
<ICDoc version="4.01">
<FechaXML>2014-10-15T12:00:09</FechaXML>
<Documento ID="6549697">
<LineasFactSinOc>
<LineaFactSinOc>
	<NUMLINEA>1</NUMLINEA>
	<IDMSTRITEM>0</IDMSTRITEM>
	<IDARTICULO>C.06.01.04.016</IDARTICULO>
	<NOMBARTICULO>Petroleo Diesel</NOMBARTICULO>
	<CANTIDAD>639.0000</CANTIDAD>
	<IDUOM>LTR</IDUOM>
	<IDMONEDA/>
	<PRECIOUNITARIO>529.800000</PRECIOUNITARIO>
	<COMENTARIOS/>
	<GLOSA/>
	<TASACAMBIO>1.000000</TASACAMBIO>
	<TOTALLINEA>338542.200000</TOTALLINEA>
	<IDLINEA>369047</IDLINEA>
	<DistribucionFactSinOc>
		<IDCENTCOSTO>00609</IDCENTCOSTO>
		<TIPODISTRIB>1</TIPODISTRIB>
		<VALOR>100.0000</VALOR>
		<IDLINEADOC>369047</IDLINEADOC>
	</DistribucionFactSinOc>
</LineaFactSinOc>
</LineasFactSinOc>
<Encabezado>
<IdDoc>
<TipoDoc>FC</TipoDoc>
<NumDoc>2441397</NumDoc>
<FolioUnico>0101-382435</FolioUnico>
<FchTransaccion>2014-05-30T17:14:30</FchTransaccion>
<FchEmis>2014-05-15</FchEmis>
<FchVenc>2014-06-14</FchVenc>
<FchRecepcion>2014-05-26</FchRecepcion>
<FchEstimadaPago>2014-06-06</FchEstimadaPago>
<Comentarios>Nombre Usuario:IROJASV Numero Lote:138634</Comentarios>
<TipoDocTributario>Afecta</TipoDocTributario>
<AgenteRetenedor>1</AgenteRetenedor>
<SinOC>true</SinOC>
<Electronico>true</Electronico>
<Estado>...</Estado>
<EstadoAsoc>...</EstadoAsoc>
<MonedaRef>...</MonedaRef>
<TipoDocFactura>...</TipoDocFactura>
</IdDoc>
<Comprador>...</Comprador>
<Proveedor>...</Proveedor>
<Totales>...</Totales>
</Encabezado>
<OtrosImpuestos>...</OtrosImpuestos>
<CuentasCosto>...</CuentasCosto>
<Cuadre ID="1283783">...</Cuadre>
</Documento>
</ICDoc>


I made the next code visual basic

VB
while reader.read()

       Select Case  XmlNodeType.Element
            
           MsgBox("Element name"+reader.name)
              
      Select Case XmlNodeType.Text

          
           MsgBox("Value Element:"+reader.value)

     Select Case XmlEndElement

           MsgBox("Node Name to Close"+reader.name)

     Exit Select

End While
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900