New Xml Converters General presentation of Xml converters The old way

Slides:



Advertisements
Similar presentations
J0 1 Marco Ronchetti - Web architectures – Laurea Specialistica in Informatica – Università di Trento Java XML parsing.
Advertisements

XML, Uploading, Importing... Joshua Scotton.
XML Parsing Using Java APIs AIP Independence project Fall 2010.
SAX A parser for XML Documents. XML Parsers What is an XML parser? –Software that reads and parses XML –Passes data to the invoking application –The application.
14-Jun-15 DOM. SAX and DOM SAX and DOM are standards for XML parsers-- program APIs to read and interpret XML files DOM is a W3C standard SAX is an ad-hoc.
©Silberschatz, Korth and Sudarshan10.1Database System Concepts W3C Activities HTML: is the lingua franca for publishing on the Web XHTML: an XML application.
28-Jun-15 StAX Streaming API for XML. XML parser comparisons DOM is Memory intensive Read-write Typically used for documents smaller than 10 MB SAX is.
Apache DOM Parser©zwzOctober 24, 2002 Wenzhong Zhao Department of Computer Science The University of Kentucky.
Processing of structured documents Spring 2003, Part 5 Helena Ahonen-Myka.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools Leonidas Fegaras.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools Leonidas Fegaras.
Networking Nasrullah. Input stream Most clients will use input streams that read data from the file system (FileInputStream), the network (getInputStream()/getInputStream()),
XML And Its UsesUPE Dearborn, 2/9/2004 ParsersCopyright 2004 by Blair Schneider McKaySlide 1 Agenda Introduction - "Why XML?" Section 1: XML Basics Section.
SAX Parsing Presented by Clifford Lemoine CSC 436 Compiler Design.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools.
XML Parsers Overview  Types of parsers  Using XML parsers  SAX  DOM  DOM versus SAX  Products  Conclusion.
SAX. What is SAX SAX 1.0 was released on May 11, SAX is a common, event-based API for parsing XML documents Primarily a Java API but there implementations.
Electronic Commerce COMP3210 Session 4: Designing, Building and Evaluating e-Commerce Initiatives – Part II Dr. Paul Walcott Department of Computer Science,
XML 6.4 DOM 6. The XML ‘Alphabet Soup’ XMLExtensible Markup Language Defines XML documents XSLExtensible Stylesheet Language Language for expressing stylesheets;
Conditions DB in LHCb LCG Conditions DB Workshop 8-9 December 2003 P. Mato / CERN.
Gaudi Framework Tutorial, XML The persistent world.
DOM Programming The Document Object Model standardises  what an application can see of the XML data  how it can access it An XML structure is a tree.
Web Technologies COMP6115 Session 4: Adding a Database to a Web Site Dr. Paul Walcott Department of Computer Science, Mathematics and Physics University.
CHEP /21/03 Detector Description Framework in LHCb Sébastien Ponce CERN.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools.
XML Study-Session: Part III
SNU OOPSLA Lab. DOM/SAX Applications The ubiquitous XML(9) © copyright 2001 SNU OOPSLA Lab.
Apache DOM Parser©zwzOctober 24, 2002 Wenzhong Zhao Department of Computer Science The University of Kentucky.
SAX2 and DOM2 Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
XML and SAX (A quick overview) ● What is XML? ● What are SAX and DOM? ● Using SAX.
Extracting Typed Values from XML Data Fabio Simeoni David Lievens Paolo Manghi Steve Neely Richard Connor.
COSC617 Project XML Tools Mark Liu Sanjay Srivastava Junping Zhang.
When we create.rtf document apart from saving the actual info the tool saves additional info like start of a paragraph, bold, size of the font.. Etc. This.
Detector Description in LHCb (Extended Version) Detector Description Workshop 4 July 2002 S. Ponce - CERN.
CHEP /21/03 Detector Description Framework in LHCb Sébastien Ponce CERN.
©Silberschatz, Korth and Sudarshan10.1Database System Concepts W3C - The World Wide Web Consortium W3C - The World Wide Web Consortium.
7-Mar-16 Simple API XML.  SAX and DOM are standards for XML parsers-- program APIs to read and interpret XML files  DOM is a W3C standard  SAX is an.
13-Mar-16 DOM. 2 Difference between SAX and DOM DOM reads the entire XML document into memory and stores it as a tree data structure SAX reads the XML.
USING ANDROID WITH THE DOM. Slide 2 Lecture Summary DOM concepts SAX vs DOM parsers Parsing HTTP results The Android DOM implementation.
XML & JSON. Background XML and JSON are to standard, textual data formats for representing arbitrary data – XML stands for “eXtensible Markup Language”
21-Jun-16 Document Object Model DOM. SAX and DOM SAX and DOM are standards for XML parsers-- program APIs to read and interpret XML files DOM is a W3C.
Java API for XML Processing
XML 1.Introduction to XML 2.Document Type Definition (DTD) 3.XML Parser 4.Example: CGI Gateway to XML Middleware.
XML. Contents  Parsing an XML Document  Validating XML Documents.
Slice & dice the Web with XmlPL, The XML Processing Language A presentation for Boise Code Camp 2007 Joseph Coffland Cauldron Development LLC.
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
In this session, you will learn to:
New Xml Converters General presentation of Xml converters The old way
Java XML IS
Server-Side Application and Data Management IT IS 3105 (FALL 2009)
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
CHAPTER 9 JAVA AND XML.
DOM Document Object Model.
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
XML in LHCb Detector Description Framework Radovan Chytracek CERN
More Sample XML By Sadia Anjum.
LHCb Detector Description Framework Radovan Chytracek CERN Switzerland
Various News From Detector Description
Detector Description in LHCb
DOM 8-Dec-18.
A parser for XML Documents
DOM 24-Feb-19.
GAUDI Detector Description News Radovan Chytracek 5/1/2019
The Calorimeter Detector Description
XML Parsers.
XML Programming in Java
LHCb Detector Description Framework Radovan Chytracek CERN Switzerland
WaysInJavaToParseXML
XML and Web Services (II/2546)
Presentation transcript:

New Xml Converters General presentation of Xml converters The old way SAX interface Consequences on efficiency The new way DOM interface The gain How to write a converter Overview of the general case The specific detector element case Why you don't need all that (thanks to Olivier and Andrei) Real life examples References and documentation

Overview of Xml Converters One converter per object type DetElem LogVol Isotope MuonStation VertexDetector ... 4 main methods in IConverter interface to be implemented createObj, updateObj, createRef, updateRef Only createObj is actually implemented An underlying XML parser is used, namely xerces C++ The actual code does a (quasi) 1 to 1 mapping between XML elements and C++ objects and between XML attributes and C++ object members.

The SAX Interface (1) SAX is an interface to the XML parser based on streaming and call-backs You need to implement the HandlerBase interface : startDocument, endDocument startElement, endElement characters warning, error, fatalError You should then give a pointer to your interface to the parser Then you call parse

The SAX Interface (2) XML File SAX calls StartDocument() <A> startElement(A) startElement(B1) startElement(C) endElement(C) endElement(B1) characters("blabla") startElement(B2) endElement(B2) endElement(A) endDocument() <A> <B1> <C/> </B1> blabla <B2/> </A> XML File SAX calls

SAX pro and contra CONTRA The file has to be parsed entirely to access any node. Thus, getting the 10 nodes included in a catalog ended up in parsing 10 times the same file. Poor navigation abilities : no way to get easily the children of a given node or the list of "B" nodes Made converters difficult to implement since the state of the parsing had to be handled by the user PRO Low memory needs since the XML file is never entirely in memory Can deal with XML streams

The DOM Interface (1) DOM is an interface to the XML parser based on tree representation of XML files One single method to parse files : parse. It returns a DOM_Document, the top node of the tree representing your file This tree is essentially made of : DOM_Element : the xml tags DOM_Text : the bunches of text in XML Comments, Attributes, ... You can navigate the tree with : getAttribute, getAttributeNode, getAttributes getChildNodes, getFirstChild, getLastChild, getParentNode getNodeName, getNodeValue GetElementsByTagName, getElementById

The DOM Interface (2) XML File DOM Tree Document <A> A (Element) <B1> <C/> </B1> blabla <B2/> </A> Document A (Element) B1 (Element) C (Element) "blabla" (Text) B2 (Element) XML File DOM Tree

DOM pro and contra PRO The file is parsed only once if you cache the DOM_Documents. A XMLParserSvc was created to encapsulate parsing and caching. The file is not even fully parsed due to parse on demand implementation in the xerces parser. High navigation abilities : this is the aim of the DOM design Converters implementation very natural. No more state. CONTRA More memory needed since the XML tree is in memory

Writing a converter (General case) XmlGenericCnv implements the whole machinery of looking for files, parsing them and getting the right DOM_Element from the tree. By inheriting from it, you only need to implement 4 methods : i_createObj (DOM_Element, DataObject*&) : creation of the C++ object (new) i_fillObj (DOM_Element, DataObject*) : called for each child of the DOM_Element that is also a DOM_Element i_fillObj (DOM_Text, DataObject*) : called for each child of the DOM_Element that is a DOM_Text i_processObj (DataObject*) : for computation In addition one should use dom2Std to convert DOM_String to std::string. DOM_String::transcode() converts DOM_String ot char* but allocates memory XmlGenericCnv provides you the member xmlSvc that provides you an expression evaluator

Writing a specific DetElem Converter Detector elements can be extended by users (tag <specific>) -> specific converters should be implemented To minimize the work, a templated class called XmlUserDetElemCnv<aType> has been created. It implements the conversion of a regular detector element. By inheriting from it, you only need to implement 1 method : i_fillSpecificObj (DOM_Element, aType*) : called for each child of the <specific> tag that is also a DOM_Element

XmlMuonStationCnv usage <detelem classID="9990" name="MStation01"> <geometryinfo lvname="..." rpath="1" support="..."/> <specific> <Al_plate_thickness value="1.2222*mm"/> </specific> </detelem> class DeMuonStation : public DetectorElement { public: DeMuonStation(); ~DeMuonStation(); double thickness(); void setThickness( double t ); private: double m_thickness; }; SmartDataPtr<DeMuonStation> station (detSvc(), "/dd/Structure/LHCb/Muon/Stations/MStation01"); if (!station) {...} log << MSG::INFO << "Aluminium plate thickness: " << station->thickness() << endreq;

XmlMuonStationCnv Static CnvFactory<XmlMuonStationCnv> muonst_factory; const IcnvFactory& XmlMuonStationCnvFactory = muonst_factory; XmlMuonStationCnv::XmlMuonStationCnv(ISvcLocator* svc) : XmlUserDetElemCnv<DeMuonStation> (svc) {} StatusCode XmlMuonStationCnv::i_fillSpecificObj (DOM_Element childElement, DeMuonStation* dataObj) { std::string tagName = dom2Std (childElement.getNodeName()); if ("Al_plate_thickness" == tagName) { const std::string value = dom2Std (childElement.getAttribute ("value")); if (!value.empty()) { dataObj->setThickness (xmlSvc()->eval(value)); } return StatusCode::SUCESS;

Avoiding writing a converter 99% of the extensions of detector element are addition of parameters. Tags userParameter and userParameterVector were added : Attributes are name, type and comment value is in plain text This is converted by the default converter XmlDetectorElementCnv Parameters are accessible in regular interface IDetectorElement via methods : string userParameter(Vector)Type (string name) string userParameter(Vector)Comment (string name) string userParameter(Vector)Value (string name) double userParameter(Vector) (string name)

Muon without converter <detelem name="MStation01"> <geometryinfo lvname="..." rpath="1" support="..."/> <userParameter name="Al_plate_thickness" type="double"> 1.2222*mm </userParameter> </detelem> SmartDataPtr<IDetectorElement> station (detSvc(), "/dd/Structure/LHCb/Muon/Stations/MStation01"); if (!station) {...} log << MSG::INFO << "Aluminium plate thickness: " << station->userParameter("Al_plate_thickness") << endreq;

Documentation / References This presentation The xerces API (http://xml.apache.org/xerces-c/apiDocs/index.xml) The Gaudi documentation :http://proj-gaudi.web.cern.ch/proj- gaudi/Doxygen/v7/doc/html/index.html and http://lhcbsoft.web.cern.ch/LHCbSoft/LHCb/v7/doc/html/index.htmlL Last versions of Det/DetDesc (v7-8) and Det/XmlDDDB (v6) packages. Especially the new TEST subdirectory of XmlDDDB. Ex/DetDescExample package where you will find some user specific detector element converters.