[Gambas-user] XML library with xml multilevel tags (EndElement)
Luigi Carlotto
md9327 at ...120...
Sat Jan 3 12:19:57 CET 2009
Il giorno dom, 28/12/2008 alle 02.14 +0100, Luigi Carlotto ha scritto:
> Il giorno sab, 27/12/2008 alle 20.04 +0100, Luigi Carlotto ha scritto:
>
> > I do not comprise the reason, but mine precedence post has been
> > included like answer in an other mail.
> >
> > … however…
> >
> >
> > Gambas 2.9.0
> >
> > Using the gb.xml library, me they are shrewed that the reading can
> > be carried out single on files xml to 2 levels.
> > I explain myself in better way…
> > I have necessity to read xml files, that it contains a composed
> > structure from elements, structured in hierarchical way on more
> > levels, as an example:
> >
> > <?xml version="1.0" encoding="UTF8"?>
> > <pgDesigner Version="2.0.0">
> > <PROJECT Name="bible" PageFormat="A4" PageOrientation="0"
> > Revision="14/03/2008 14:44:03" Description="bible" Driver="8.2"
> > Author="mgm" Display="0">
> > <TABLE Name="tb_log" X="10" Y="6" ColorBack="230,230,230"
> > ColorText="0,0,0" ColorBackTitle="230,230,230"
> > ColorBackTitleSelected="76,89,166" ColorForeTitle="0,0,0"
> > ColorForeTitleSelected="255,255,255" Comment="006C006F0067"
> > Option="false" PrimaryKey="tb_log_pk">
> > <TABLEFIELD Name="id" Table="tb_log"
> > Comment="006900640065006E00740069006600690061006E0074" Length="0"
> > NullCheck="true" PrimaryKey="true" Type1="serial"/>
> > <INDEX Name="tb_type_personne_idx1" Table="tb_type_personne"
> > Unique="true"/>
> > </TABLE>
> > questa è una prova
> > </PROJECT>
> > </pgDesigner>
> >
> > In the example, the hierarchy of the rows xml is composed gives:
> > 1) a main element (root) “<pgDesigner>”;
> > 2) inside of the root, the element is present “<PROJECT>”;
> > 3) under “<PROJECT>” the element is present “<TABLE>”;
> > 4) in its turn, the element “<TABLE>” contains a series of other
> > heterogenous elements.
> >
> > Through the gb.xml library, the reading of the file does not notice
> > of the closing of tag (Node.Type=XmlReaderNodeType.EndElement), if
> > these are sluices on the same definition of the tag, like as an
> > example:
> >
> > <INDEX Name="tb_type_personne_idx1" Table="tb_type_personne"
> > Unique="true"/>
> >
> > the reading evidences the opening of tag, but the not its closing,
> > for which it renders impossible to ago understand if tag following
> > the part of a advanced element, or is to the same level of the
> > element precedence.
> >
> > The behavior is various in phase of writing where, through the
> > methods “StartElement” and “EndElement”, it is possible to define
> > complex structures.
> >
> > This logic, currently, only forces the use of structures xml on two
> > levels.
>
>
> The spaces contained in the strings do not have particolary functions,
> but they make part of the name of the object, and it is not possible
> to eliminate them.
> In other cases, use the comma in order to separate a list of elements
> (es. an Array, Join function), than in reading comes reconverted in
> Array (Split function).
>
> With regard to the levels, I have resolved, constructing a series of
> classes, based on the objects XmlReader and XmlWriter.
> Logic of these objects allows to only read to rows xml multilevel, but
> if the tag they are not sluices on if same. In contrary case, the
> gb.xml library does not notice of the closing of the tag, for which
> the hierarchy it does not come constructed in correct way.
>
> These classes directly work in memory, loading the xml files in a
> structure, that it can be read inside of a program.
> The writing comes carried out through the same structure of memory.
> This logic me slightly seems or faster, and fastly releases the
> connections to the file.
>
> Only problem, perhaps, could be the management of large files; I have
> tried with xml of 2Mbyte, and I am fast.
> Perhaps he can be useful in Gambas…
> The structure follows logic, also applied in other languages, than
> part from an object Document (pgXmlDocument), that a Root element
> contains; like then for all the other elements (pgXmlElement), it
> contains an Array of elements and an Array of attributes
> (pgXmlAttribute).
> The connection with the object father, comes managed from the property
> Parent (Root does not have Parent, obviously).
>
> It makes me to know if it can interest.
Like the last ones, also this mail has not arrived in the mailing list…
However, I have uncovered qual'è the problem with the management of tag
the multilevel.
If the tag it comes closed, immediately after the list of the
attributes, like as an example:
<tag attribute=""/>
the variable “XmlReaderNodeType.EndElement” does not come set up.
If the tag it comes in this way closed:
<tag attribute=""></tag>
the closing comes found, and the variable “XmlReaderNodeType.EndElement”
works correctly; in this way it can be understood if the tag it contains
other elements, and this allows to manage a document xml in modality
multilevel.
I have executed some modifications to my code, and the xml files, and
all it works like previewed.
At the same time, I have constructed to a series of generic classes,
that they join the functionalities of the two classes XmlReader and
XmlWriter, and that they work directly in memory, loading an inner
structure given (Array with objects), the reading and the rescue of the
document xml is executed in an only phase.
I have executed some tests, and with files of 2Mbyte problems are not
taken place, and the operations are fast.
I task that, in order to obtain a dynamic gb.xml library, is perhaps the
case to modify the reading methods, so as to find these varying in the
xml files.
More information about the User
mailing list