| Ver tema anterior :: Ver tema siguiente |
| Autor |
Mensaje |
Angel Master


Registrado: 15 Abr 2003Mensajes: 2311Ubicación: Toledo (España)
|
Publicado: Jue 07 Ago, 2014 9:12 am Asunto: Leer un fichero en XML |
|
|
Después de muchas peripecias logré instalar el componente TXMLDocument. Ahora me viene otro problema: Por más que miro la ayuda no soy capaz de entender como se recorre un fichero en este formato con ese elemento. Me he hartado de buscar documentación pero no he encontrado, o no he sabido hacerlo, prácticamente nada. ¿Podéis facilitarme algún sitio en qué encontrar documentación sobre este componente? _________________ Un saludo
Necesitamos tu ayuda: Envía AI al 27595 (Coste 1,20 euros + IVA) |
|
| Volver arriba |
|
 |
frios Lt

Registrado: 20 Nov 2005Mensajes: 79Ubicación: España
|
Publicado: Jue 07 Ago, 2014 11:19 am Asunto: |
|
|
Hola. Yo uso ese componente para crear los archivos XML que usa SEPA.
Solo los genero, no los leo, pero supongo que será similar.
En principio se usa como un TreeView. Te adjunto un ejemplo de código.
| Código: | _di_IXMLNode iNode;
_di_IXMLNode iNodeLevel,iNodeLevel1,iNodeLevel2,iNodeLevel3;
bool blSuccess = true;
try
{
XMLDocument1->Active = false;
XMLDocument1->FileName = "";
XMLDocument1->Active = true; |
| Código: | //RAIZ DEL MENSAJE
XMLDocument1->DocumentElement = XMLDocument1->CreateElement("CstmrDrctDbtInitn", "");
//INICIO CABECERA
iNode = XMLDocument1->DocumentElement->AddChild(WideString("GrpHdr"));
iNodeLevel = iNode->AddChild(WideString("MsgId")); //++identificación mensaje
//iNodeLevel->SetAttribute("value", "TCrawsComponent.zip");
String valor;
valor = EditCifOrdenante->Text + "-" + FormatDateTime("yymmdd-hh:nn",Now());
iNodeLevel->SetNodeValue(valor); //35
iNodeLevel = iNode->AddChild(WideString("CreDtTm")); //++Fecha hora creacion
valor = FormatDateTime("yyyy-mm-dd hh:nn:ss",Now());
iNodeLevel->SetNodeValue(StringReplace(valor, " ", "T", TReplaceFlags() <<rfReplaceAll>AddChild(WideString("NbOfTxs")); //++Numero operaciones
|
| Código: | //INICIO INFORMACION DE PAGO
iNode = XMLDocument1->DocumentElement->AddChild(WideString("PmtInf"));
iNodeLevel = iNode->AddChild(WideString("PmtInfId")); //identificaion de la informacion de pago
valor = EditCifOrdenante->Text + "-" + FormatDateTime("yymmdd-hh:nn",Now()) + "-1";
iNodeLevel->SetNodeValue(valor); //35
iNodeLevel = iNode->AddChild(WideString("PmtMtd")); //metodo de pago
iNodeLevel->SetNodeValue("DD"); //2 (Direct Debit)
|
Suerte |
|
| Volver arriba |
|
 |
Angel Master


Registrado: 15 Abr 2003Mensajes: 2311Ubicación: Toledo (España)
|
Publicado: Jue 07 Ago, 2014 11:22 am Asunto: |
|
|
Muchas gracias. Precisamente para leer las devoluciones de SEPA me hace falta. No obstante exprimiré el código porque me terminará haciendo falta grabar en XML porque en 2016 sólo aceptarán este formato. _________________ Un saludo
Necesitamos tu ayuda: Envía AI al 27595 (Coste 1,20 euros + IVA) |
|
| Volver arriba |
|
 |
juanma Cmdr

Registrado: 17 Nov 2005Mensajes: 127Ubicación: Almeria - España
|
Publicado: Jue 07 Ago, 2014 1:33 pm Asunto: |
|
|
El ejemplo que pongo aquí lo utilice para entender un poco el componente TXMLDocument, no tengo mas código ya que al final los desarrollos que tengo usando XML los he realizado en C# (esto es con el C++builder 2007)
| Código: |
void __fastcall TfMainXML::bOpenClick(TObject *Sender)
{
const int MAXLV = 19; // big
bool lnx = false;
int nC, nlv, nml, nln;
int ncn[MAXLV];
String cN, cV;
_di_IXMLNode NdAt, NdDt;
_di_IXMLNodeList Atrb;
// error - XMLDoc->LoadFromXML((String)"ejemplo.xml");
//XMLDoc->FileName = "ejemplo.xml";
//XMLDoc->Active = true; ok.
XMLDoc->LoadFromFile("ejemplo.xml");
NdDt = XMLDoc->DocumentElement;
//Memo1->Lines->Add(NdDt->Attributes["xmlns"]); // 'Open XML' - Null???
Atrb = NdDt->GetAttributeNodes();
for (int i = 0; i <Atrb>Count; i++) {
NdAt = Atrb->Get(i);
cN = NdAt->GetNodeName();
Memo1->Lines->Add("Atr Name: " + cN);
Memo1->Lines->Add(" " + NdDt->Attributes[cN]);
}
nlv = nml = nln = 0; //nlv:key, nml+nln:info
ncn[0] = NdDt->ChildNodes->Count;
NdDt = NdDt->ChildNodes->GetNode(0);
while (ncn[nlv] > 0) {
ncn[nlv] --;
if (NdDt->GetNodeType() == ntCData)
cN = "CDt: " + NdDt->GetNodeValue();
else // if (.. ntElement ..)
cN = NdDt->GetNodeName();
Memo1->Lines->Add("Nodo " + IntToStr(nlv+1) + ": " + cN);
nln++;
Atrb = NdDt->GetAttributeNodes();
for (int i = 0; i <Atrb>Count; i++) {
NdAt = Atrb->Get(i);
cN = NdAt->GetNodeName();
cV = NdDt->Attributes[cN];
Memo1->Lines->Add(" AtName: " + cN + " = " + cV);
}
lnx = true;
if (NdDt->IsTextElement) {
cV = NdDt->GetText();
Memo1->Lines->Add(" " + cV);
} else {
nC = NdDt->ChildNodes->Count;
if (nC > 0 && nlv <MAXLV>ChildNodes->GetNode(0);
lnx = false;
}
}
if (nlv > nml) nml = nlv;
if (lnx) {
while (ncn[nlv] == 0 && nlv > 0) {
nlv --;
NdDt = NdDt->GetParentNode();
}
if (ncn[nlv] > 0)
NdDt = NdDt->NextSibling();
}
}
lbLn->Caption = IntToStr(nln); //nº nodos
lbMD->Caption = IntToStr(nml+1); //max ch
XMLDoc->Active = false;
}
|
Para el fichero de prueba 'ejemplo.xml' renombraba el mismo del proyecto de c++builder, que en el 2007 era en formato xml.
Saludos,
Juanma |
|
| Volver arriba |
|
 |
Angel Master


Registrado: 15 Abr 2003Mensajes: 2311Ubicación: Toledo (España)
|
Publicado: Vie 08 Ago, 2014 9:20 am Asunto: |
|
|
Muchas gracias por la ayuda. Estudiaré con atención el código que habéis subido los dos. Es una lástima la poca documentación que hay sobre este componente.
He estado viendo código en Delphi y el que me has puesto ahora. Me llama la atención una coas: ¿Qué diferencia hay entre IXMLNode y TXMLNode? _________________ Un saludo
Necesitamos tu ayuda: Envía AI al 27595 (Coste 1,20 euros + IVA) |
|
| Volver arriba |
|
 |
Angel Master


Registrado: 15 Abr 2003Mensajes: 2311Ubicación: Toledo (España)
|
Publicado: Vie 08 Ago, 2014 9:42 am Asunto: |
|
|
Juanma: Hay una línea en tu código que no sé como interpretar. Se ve que tenías habilitado el HTML en el mensaje y se ha comido algunos símbolos. En concreto es esta:
| Código: | if (nC > 0 && nlv <MAXLV>ChildNodes->GetNode(0); |
_________________ Un saludo
Necesitamos tu ayuda: Envía AI al 27595 (Coste 1,20 euros + IVA) |
|
| Volver arriba |
|
 |
juanma Cmdr

Registrado: 17 Nov 2005Mensajes: 127Ubicación: Almeria - España
|
Publicado: Lun 11 Ago, 2014 8:41 am Asunto: |
|
|
Esperemos que ahora no se coma nada
| Código: | void __fastcall TfMainXML::bOpenClick(TObject *Sender)
{
const int MAXLV = 19; // big
bool lnx = false;
int nC, nlv, nml, nln;
int ncn[MAXLV];
String cN, cV;
_di_IXMLNode NdAt, NdDt;
_di_IXMLNodeList Atrb;
// error - XMLDoc->LoadFromXML((String)"ejemplo.xml");
//XMLDoc->FileName = "ejemplo.xml";
//XMLDoc->Active = true; ok.
XMLDoc->LoadFromFile("ejemplo.xml");
NdDt = XMLDoc->DocumentElement;
//Memo1->Lines->Add(NdDt->Attributes["xmlns"]); // 'Open XML' - Null???
Atrb = NdDt->GetAttributeNodes();
for (int i = 0; i < Atrb->Count; i++) {
NdAt = Atrb->Get(i);
cN = NdAt->GetNodeName();
Memo1->Lines->Add("Atr Name: " + cN);
Memo1->Lines->Add(" " + NdDt->Attributes[cN]);
}
nlv = nml = nln = 0; //nlv:key, nml+nln:info
ncn[0] = NdDt->ChildNodes->Count;
NdDt = NdDt->ChildNodes->GetNode(0);
while (ncn[nlv] > 0) {
ncn[nlv] --;
if (NdDt->GetNodeType() == ntCData)
cN = "CDt: " + NdDt->GetNodeValue();
else // if (.. ntElement ..)
cN = NdDt->GetNodeName();
Memo1->Lines->Add("Nodo " + IntToStr(nlv+1) + ": " + cN);
nln++;
Atrb = NdDt->GetAttributeNodes();
for (int i = 0; i < Atrb->Count; i++) {
NdAt = Atrb->Get(i);
cN = NdAt->GetNodeName();
cV = NdDt->Attributes[cN];
Memo1->Lines->Add(" AtName: " + cN + " = " + cV);
}
lnx = true;
if (NdDt->IsTextElement) {
cV = NdDt->GetText();
Memo1->Lines->Add(" " + cV);
} else {
nC = NdDt->ChildNodes->Count;
if (nC > 0 && nlv < MAXLV-1) {
nlv ++;
ncn[nlv] = nC;
NdDt = NdDt->ChildNodes->GetNode(0);
lnx = false;
}
}
if (nlv > nml) nml = nlv;
if (lnx) {
while (ncn[nlv] == 0 && nlv > 0) {
nlv --;
NdDt = NdDt->GetParentNode();
}
if (ncn[nlv] > 0)
NdDt = NdDt->NextSibling();
}
}
lbLn->Caption = IntToStr(nln); //nº nodos
lbMD->Caption = IntToStr(nml+1); //max ch
XMLDoc->Active = false;
}
|
|
|
| Volver arriba |
|
 |
Angel Master


Registrado: 15 Abr 2003Mensajes: 2311Ubicación: Toledo (España)
|
|
| Volver arriba |
|
 |
|