Banana.Xml

Cette documentation est dépassée

La documentation la plus complète et actualisée est celle de Banana Comptabilité Plus : Essayez-le maintenant

In this article

The Banana.Xml class is used to parse and access xml data.​

Since: Banana Accounting 8.0.5

Introduction

The API Banana.Xml and Banana.Xml.XmlElement implement a subset of the DOM Document Object Model interface.  The most used properties and methos are implemented.

For example the list of books in the following xml file:

<Library updated="2016-10-31">
   <Book>
      <Title>Paths of colours</Title>
      <Author>Rosa Indaco</Author>
   </Book>
   <Book>
      <Title>Accounting exercises</Title>
      <Author>Su Zhang</Author>
   </Book>
</Library>

Can be retrieved with the following code:

var xmlFile = Banana.Xml.parse(xml); 
var xmlRoot = xmlFile.firstChildElement('Bookshelf'); 
var updateDate = xmlRoot.attribute('updated');
var bookNode = xmlRoot.firstChildElement('Book');  // First book
while (bookNode) { 
   // For each book in the library
   var title = xmlFile.firstChildElement('Title').text();
   var authorNode = xmlFile.firstChildElement('Author'); 
   var author = authorNode ? authorNode.text() : 'unknow';
   bookNode = bookNode.nextSiblingElement('Book');  // Next book
} 

 

Methods

parse(xml)

The method parse(xml) parses xml data and returns an object of type Banana.Xml.XmlElment that represents the parsed xml. If the xml data is not valid, this method returns null.

var xmlFile = Banana.Xml.parse(xml); 
var xmlRoot = xmlFile.firstChildElement('Bookshelf'); // The root element is named 'Bookshelf' in this example

Partager cet article: Twitter | Facebook | LinkedIn | Email