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

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.
1 XML and Data Management XML Processors Hachim Haddouti Al Akhawayn University SSE
MC365 XML Parsers. Today We Will Cover: An overview of the Java API’s used for XML processing Creating an XML document in Java Parsing an XML document.
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()),
5 Processing XML Parsing XML documents  Document Object Model (DOM)  Simple API for XML (SAX) Class generation Overview.
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.
Advanced Java Session 9 New York University School of Continuing and Professional Studies.
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.
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.
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.
1 Introduction JAXP. Objectives  XML Parser  Parsing and Parsers  JAXP interfaces  Workshops 2.
CHEP /21/03 Detector Description Framework in LHCb Sébastien Ponce CERN.
Detector Description in LHCb Detector Description Workshop 13 June 2002 S. Ponce, P. Mato / 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.
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.
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.
New Xml Converters General presentation of Xml converters The old way
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
In this session, you will learn to:
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.
Processing XML.
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
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.
Document Object Model (DOM): Objects and Collections
A parser for XML Documents
DOM 24-Feb-19.
Python and XML Styling and other issues XML
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 What we gain How to write a converter Overview (general case and specific detector element case) 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) Parse() Converter Parser StartElement (...) SAX is an interface to the XML parser based on streaming and call-backs You first 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 Parse() Converter Parser StartElement (...) EndElement (...)

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) Parse(...) Converter Parser 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_Attr : the xml attributes DOM_Text : the bunches of text in XML You can navigate the tree with : getAttribute, getAttributeNode, getAttributes getChildNodes, getFirstChild, getLastChild, getParentNode getNodeName, getNodeValue GetElementsByTagName, getElementById Converter Parse(...) Parser

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. Still better, the file is not fully parsed if not necessary 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 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 can be made 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

XmlSurfaceCnv (1) // Instantiation of a static factory class used by clients to create instances of this service static CnvFactory<XmlSurfaceCnv> s_FactoryXmlSurfaceCnv; const ICnvFactory& XmlSurfaceCnvFactory = s_FactoryXmlSurfaceCnv; // Empty Constructor XmlSurfaceCnv::XmlSurfaceCnv (ISvcLocator* svc) : XmlGenericCnv (svc, classID()) {}; StatusCode XmlSurfaceCnv::i_createObj (DOM_Element element, DataObject*& refpObject) { // Object creation std::string elementName = dom2Std (element.getAttribute ("name")); Surface* dataObj= new Surface (elementName); refpObject = dataObj; // model attribute const std::string value = dom2Std (element.getAttribute ("model")); const double v_value = xmlSvc()->eval(value, false); dataObj->setModel (v_value); ... } // end i_createObj

XmlSurfaceCnv (2) StatusCode XmlSurfaceCnv::i_fillObj (DOM_Element childElement, DataObject* refpObject) { // gets the object Surface* dataObj = dynamic_cast<Surface*> (refpObject); // gets the element's name std::string tagName = dom2Std (childElement.getNodeName()); // dispatches, based on the name if ("tabprops" == tagName) { const std::string address = dom2Std (childElement.getAttribute ("address")); long linkID = dataObj->addLink(address, 0); ... } else { }

Writing a specific DetElem Converter Detector elements can be extended by users (tag <specific>) To minimize the work, a templated class called XmlUserDetElemCnv<aType> has been created. It implements the whole 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 // Instantiation of a static factory class used by clients to create instances of this service Static CnvFactory<XmlMuonStationCnv> muonst_factory; const ICnvFactory& XmlMuonStationCnvFactory = muonst_factory; // Empty Constructor XmlMuonStationCnv::XmlMuonStationCnv(ISvcLocator* svc) : XmlUserDetElemCnv<DeMuonStation> (svc) {} StatusCode XmlMuonStationCnv::i_fillSpecificObj (DOM_Element childElement, DeMuonStation* dataObj) { // gets the element's name std::string tagName = dom2Std (childElement.getNodeName()); if ("Al_plate_thickness" == tagName) { // get a value of the 'value' attribute const std::string value = dom2Std (childElement.getAttribute ("value")); if (!value.empty()) { dataObj->setThickness (xmlSvc()->eval(value)); } } else { ...

Documentation 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.html The Ex/DetDescExample package where you can find some user specific detector element converters.