StRoot
1
|
#include <StlXmlTree.h>
Public Member Functions | |
StlXmlTree (const std::string xmlfilename, StlXmlTree *filter=0) | |
void | ShowTree () |
std::vector< std::string > | LookUpValueByKey (const std::string key) |
std::vector< std::string > | LookUpValueByKey (std::string &Parent, const std::string ParentAttributes, const std::string Child) |
void | InsertKeyValuePair (std::string key, std::string value) |
short | GetStatus () |
Name: StlXmlTree
Author: Mikhail Kopytin
Date: 08/29/2006
Example: A B C
XmlTree contains: >a() – #text=A; >a()(#text=A;)>b() – #text=B;
As one can see, the information in the tree provides a self-guided way to retrieve information associated with a node based on the operation opposite to parsing, namely string concatenation, followed by a map look-up.
Attributes are treated much like regular content: there is no separate data structure to hold them. libxml2 checks to ensure a one-to-one correspondence between a set of attribute names and a set of attribute values.
Example: this is B1 this is B2
XmlTree contains: >a()>b – c=C;cc=CC1; >a()>b – c=XXX;ccc=CCC; >a()>b – c=C2; >a()>b(c=C2;) – #text=thisisB2;
4.1 Data structure.
Initially the parser receives information from the user, such as server scope, site name, and so on. (http://www.star.bnl.gov/STAR/comp/sofi/FileCatalog/schema/SCATALOG.html) That information is used to build parts of the tree. Later, information with contradicting values will be ignored. For example, if user's credentials say his site is BNL, then information related to LBL will be ignored ("vetoed"). The information describing the vetoing is stored in another StlXmlTree object. I use two instances of a single XML-parsing class, one to hold user's info without vetoing anything, the other using the first as a veto holder (filter) in a conditional tree-building process. The filter is therefore an optional property of an StlXmlTree object. If the filter is absent, parse unconditionally.
4.2 Interaction with the filter.
In the subsequent discussion we distinguish a filter file (XML instance) from a 'base' file (XML instance). The purpose of a filter file is to control selection of a subset of a base file. The filter file is an XML file which may or may not follow the same schema as the base file. Information in the filter file has a veto right on the base XML file content, rather than being a prerequisite for accepting the content. In other words, the system defaults to accepting maximum content unless explicit contradiction between filter and base file data is found (is "greedy").
Example: The base file contains: A<...> If the filter file contains <t>test</t> or A or then the base file will be fully parsed.
If the filter file contains Another a then the base file will be fully skipped.
Selective parsing examples: The base file contains:
this is c
<o> more stuff </o>
XmlTree contains: >a – a1=A1; >a(a1=A1;)>b – b1=B1;b2=B2; >a(a1=A1;)>b – b1=111;b2=222; >a(a1=A1;)>b(b1=111;b2=222;)>c – c1=C1; >a(a1=A1;)>b(b1=111;b2=222;)>c(c1=C1;) – #text=thisisc; >a(a1=A1;)>b(b1=B1;b2=B2;)>c – c1=B1C1;
If the filter file contains then the content of the base file is fully skipped.
If a filter node contains attributes not found in the base file, the content of the node is accepted unconditionally. Example: if the filter file contains the content of the base file is fully accepted.
Example: select stuff belonging to b-node with attributes b1="111", b2="222". Filter file:
XmlTree contains: >a – a1=A1; >a(a1=A1;)>b – b1=111;b2=222; >a(a1=A1;)>b(b1=111;b2=222;)>c – c1=C1; >a(a1=A1;)>b(b1=111;b2=222;)>c(c1=C1;) – #text=thisisc;
Content of the (and its very existence) has been ignored. This had no implication on the <o>...</o> node.
If attributes of a node are not fully described in the filter file, the content of the node is accepted unconditionally.
Example: Base file:
this is c
this is another c
Filter file:
XmlTree contains: >a – a1=A1; >a(a1=A1;)>b – b1=111;b2=222; >a(a1=A1;)>b(b1=111;b2=222;)>c – c1=C1; >a(a1=A1;)>b(b1=111;b2=222;)>c – c1=anotherc; >a(a1=A1;)>b(b1=111;b2=222;)>c(c1=C1;) – #text=thisisc;
To select "another c" only, use
XmlTree contains: >a – a1=A1; >a(a1=A1;)>b – b1=111;b2=222; >a(a1=A1;)>b(b1=111;b2=222;)>c – c1=anotherc;
Currently white spaces, tabulation symbols, new lines are removed.
Definition at line 247 of file StlXmlTree.h.