[Lazarus] How to get the package version from a LPK file?
Hans-Peter Diettrich
DrDiettrich1 at aol.com
Tue Nov 29 09:23:53 CET 2011
Graeme Geldenhuys schrieb:
> F*cken hell, now I know why I don't EVER use or work with XML! I had
> a look at your code, and the problem is seemingly easy, but the
> solution is definitely not. I tried DocumentElement,
> .GetElementsByName(), FindNode(), FirstChild() etc... Not a single one
> returns what I would have expected - most functions simply returned
> nil. TDOMNode.FindNode() doesn't even have an implementation.
Right, using XML without documentation sucks :-(
I had the same impression when I tried to implement XML output of fpdoc
projects right now.
> I then thought I would look at Lazarus's TXMLConfig - because surely
> that uses the DOM to find values. To my surprise, that component
> implements it's own recursive iteration over nodes to find something -
> and it's not easy on the eyes. So what the hell is the point of the
> DOM or TXMLDocument implementation if none of the default
> implementation can do any searching.
I'm not sure why the XML implementation is cluttered into an stack of
derived classes, when only TDomElement is halfways usable.
> And to be clear, as a programmer, this is the API interface I would
> expect to use... which I don't think is unreasonable. Obviously this
> doesn't work, but hey, that's XML for you.
>
> ReadXMLFile(VXML, ExtractFilePath(ParamStr(0)) + 'LazSolutionsDT.lpk');
> n := vxml.FindNode('/Config/Package/Version');
> n.Attributes.GetNamedItem('Major');
> n.Attributes.GetNamedItem('Minor');
Problem is: typical XML files (see the fpdoc files) have entries of the
same name, which has to be interpreted as a node *class* name. The
individual node names reside in some arbitrary attribute, maybe 'name',
maybe 'key' or something else. That makes a general Find method near
impossible :-(
DoDi
More information about the Lazarus
mailing list