3
Allah Personal I have the following problem: I need to create an xml file of products, in which each product will have a group, so far so good, just by adding the data it creates the product tag and within it creates the group, only by creating the product and going to add the group it is always doing as follows finds the first product tag and adds all groups. So how would I make it to always add group to the latest product tag.
Expected result:
<?xml version="1.0"?>
-<fdv>
<data>05/12/2012 17:41:08</data>
<vendedor>V001</vendedor>
-<valores>
-<produto>
<codigoImport>000083</codigoImport>
<descricao>MAÇANETA GOL</descricao>
<un>PÇ</un>
<precoVenda>12.5</precoVenda>
<estoque>180</estoque>
<codBarras>00000833</codBarras>
<url>http://user.img.todaoferta.uol.com.br/5/P/JO/NDEDP</url>
<obs>Aplicado em veículo modelo: 2001 2002 2003</obs>
-<grupo>
<codigoImport>1001</codigoImport>
<descricao>PORTAS</descricao>
</grupo>
</produto>
-<produto>
<codigoImport>000084</codigoImport>
<descricao>MAÇANETA PALIO</descricao>
<un>PÇ</un>
<precoVenda>15</precoVenda>
<estoque>200</estoque>
<codBarras>00000840</codBarras>
<url>http://www.takamineacessorios.com.br/prdfotos/prd_</url>
<obs>Aplicados em modelos: 2006 2007 2008 2009 2010</obs>
-<grupo>
<codigoImport>1001</codigoImport>
<descricao>PORTAS</descricao>
</grupo>
</produto>
</valores>
</fdv>
This is my code according to the example of Marco Antonio Quintal, now as I said he is only creating the last record:
#define Windows_Application
using System;
using System.Data;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Collections;
using System.Xml.Linq;
using System.Xml.XPath;
namespace GSD
{
class XmlProduto3
{
//Diretorio do arquivo Xml;
private string diretorioArqXml()
{
string diretorio = Directory.GetCurrentDirectory();
string mensagem = String.Empty;
string caminho = diretorio.Trim() + @"\XML\";
if (!Directory.Exists(caminho))
{
Directory.CreateDirectory(caminho);
}
return caminho;
}
//Cria o arquivo Xml;
public void criarArqXml()
{
string caminho = diretorioArqXml() + "impprodutos.xml";
string sqlFunCod = @"SELECT FUNCOD FROM SYS_USUARIO WHERE CODUSU = " + Engebuilder.Library.ConstEngebuilder.codUsu.ToString().Trim() + "";
string funcod = Engebuilder.Library.LDataAccess.GetDataToString(sqlFunCod);
Engebuilder.Library.LDataAccess.ExecuteCommand(sqlFunCod);
ArrayList VlrProCod = new ArrayList();
ArrayList VlrProDes = new ArrayList();
ArrayList VlrProUni = new ArrayList();
ArrayList VlrProPrc = new ArrayList();
ArrayList VlrProEst = new ArrayList();
ArrayList VlrProCodBar = new ArrayList();
ArrayList VlrProCodGrp = new ArrayList();
ArrayList VlrProDesGrp = new ArrayList();
DataSet ds = Engebuilder.Library.LDataAccess.GetDataSet("SELECT "
+ " PRODUTO.PROCOD, "
+ " PRODUTO.PRODESRDZ, "
+ " PRODUTO.PROUNID, "
+ " PRODUTO.PROPRCVDAVAR, "
+ " ESTOQUE.ESTATU, "
+ " PRODUTOAUX.PROCODAUX, "
+ " PRODUTO.GRPCOD, "
+ " GRUPO.GRPDES "
+ " FROM PRODUTO "
+ " INNER JOIN ESTOQUE ON ESTOQUE.PROCOD = PRODUTO.PROCOD "
+ " LEFT JOIN PRODUTOAUX ON PRODUTOAUX.PROCOD = PRODUTO.PROCOD "
+ " LEFT JOIN GRUPO ON GRUPO.GRPCOD = PRODUTO.GRPCOD "
+ " ORDER BY PRODUTO.PROCOD");
foreach (DataRow row in ds.Tables[0].Rows)
{
VlrProCod.Add(row["PROCOD"].ToString().Trim());
VlrProDes.Add(row["PRODESRDZ"].ToString().Trim());
VlrProUni.Add(row["PROUNID"].ToString().Trim());
VlrProPrc.Add(row["PROPRCVDAVAR"].ToString().Trim());
VlrProEst.Add(row["ESTATU"].ToString().Trim());
VlrProCodBar.Add(row["PROCODAUX"].ToString().Trim());
VlrProCodGrp.Add(row["GRPCOD"].ToString().Trim());
VlrProDesGrp.Add(row["GRPDES"].ToString().Trim());
}
for (int i = 0; i < VlrProCod.Count; i++)
{
XDocument doc = new XDocument(
new XElement("fdv",
new XElement("data", DateTime.Now.ToString()),
new XElement("vendedor", funcod),
new XElement("produto",
new XElement("codigoImport", VlrProCod[i].ToString()),
new XElement("descricao", VlrProDes[i].ToString()),
new XElement("un", VlrProUni[i].ToString()),
new XElement("precoVenda", VlrProPrc[i].ToString()),
new XElement("estoque", VlrProEst[i].ToString()),
new XElement("grupo",
new XElement("codigoImport", VlrProCodGrp[i].ToString()),
new XElement("descricao", VlrProDesGrp[i].ToString()
)
)
)
)
);
doc.Save(caminho);
}
MessageBox.Show("Dados exportado com sucesso!", "Atenção!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
Welcome to [en.so], post the code you’ve already made, it makes it easy for people to help you, see How to create a minimal, complete and verifiable example, then you can also do a [tour] and know how Sopt works.
– mateusalxd