0.3.2 XMLWriter

This commit is contained in:
rob tillaart 2021-12-29 16:27:03 +01:00
parent 5fe2902341
commit 67649651b0
18 changed files with 83 additions and 64 deletions

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2013-2021 Rob Tillaart Copyright (c) 2013-2022 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -1,12 +1,14 @@
[![Arduino CI](https://github.com/RobTillaart/XMLWriter/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) [![Arduino CI](https://github.com/RobTillaart/XMLWriter/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/XMLWriter/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/XMLWriter/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/XMLWriter/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/XMLWriter/actions/workflows/jsoncheck.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/XMLWriter/blob/master/LICENSE) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/XMLWriter/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/XMLWriter.svg?maxAge=3600)](https://github.com/RobTillaart/XMLWriter/releases) [![GitHub release](https://img.shields.io/github/release/RobTillaart/XMLWriter.svg?maxAge=3600)](https://github.com/RobTillaart/XMLWriter/releases)
# XMLWriter # XMLWriter
Arduino Library to create simple XML (messages, files, print, ...) Arduino Library to create simple XML (messages, files, print, ...).
## Description ## Description
@ -18,9 +20,9 @@ When instantiating an XMLWriter one can define the internal buffer size.
A bigger buffer will make the output faster, especially for Ethernet and SD.File. A bigger buffer will make the output faster, especially for Ethernet and SD.File.
The buffer size should be at least 2 bytes and max 250. The buffer size should be at least 2 bytes and max 250.
How much faster depends on the properties of the stream and the platform used. How much faster depends on the properties of the stream and the platform used.
E.g. the baudrate and internal buffer of Serial, packet behaviour of Ethernet, E.g. the baud rate and internal buffer of Serial, packet behaviour of Ethernet,
or paging of SD cards. or paging of SD cards.
If performance is low one should do testruns with different sizes for the buffer If performance is low one should do test runs with different sizes for the buffer
and choose one that is appropriate. and choose one that is appropriate.
Indicative sizes based upon the examples. Indicative sizes based upon the examples.
@ -128,12 +130,13 @@ can inject strings.
## Configuration flags ## Configuration flags
| Flag | Value | Description | | Flag | Value | Description |
|:-----------------|:------|:-------------| |:-----------------|:------|:------------------|
|XMLWRITER_NONE | 0x00 | minimize output, smaller & faster | |XMLWRITER_NONE | 0x00 | minimize output, smaller & faster |
|XMLWRITER_COMMENT | 0x01 | allow comments | |XMLWRITER_COMMENT | 0x01 | allow comments |
|XMLWRITER_INDENT | 0x02 | allow indentation | |XMLWRITER_INDENT | 0x02 | allow indentation |
|XMLWRITER_NEWLINE | 0x04 | allow newlines | |XMLWRITER_NEWLINE | 0x04 | allow newlines |
- **setConfig(XMLWRITER_NONE);** to minimize the output in bytes. - **setConfig(XMLWRITER_NONE);** to minimize the output in bytes.
- **setConfig(XMLWRITER_NEWLINE);** to break an XML stream in lines. - **setConfig(XMLWRITER_NEWLINE);** to break an XML stream in lines.
@ -149,4 +152,6 @@ See examples
## Future ## Future
- update documentation - update documentation
- -

View File

@ -1,7 +1,7 @@
// //
// FILE: XMLWriter.cpp // FILE: XMLWriter.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.3.1 // VERSION: 0.3.2
// DATE: 2013-11-06 // DATE: 2013-11-06
// PURPOSE: Arduino library for creating XML // PURPOSE: Arduino library for creating XML
// //
@ -26,7 +26,7 @@
// 0.3.1 2021-11-11 refactor naming to improve readability // 0.3.1 2021-11-11 refactor naming to improve readability
// update build-CI, // update build-CI,
// update readme.md, Badges. // update readme.md, Badges.
// // 0.3.2 2021-12-29 update library.json, readme, license, unit test, minor edits
#include "XMLWriter.h" #include "XMLWriter.h"
@ -427,3 +427,4 @@ void XMLWriter::escape(const char* str)
// -- END OF FILE -- // -- END OF FILE --

View File

@ -2,7 +2,7 @@
// //
// FILE: XMLWriter.h // FILE: XMLWriter.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.3.1 // VERSION: 0.3.2
// DATE: 2013-11-06 // DATE: 2013-11-06
// PURPOSE: Arduino library for creating XML // PURPOSE: Arduino library for creating XML
// //
@ -11,40 +11,40 @@
#include "Arduino.h" #include "Arduino.h"
#define XMLWRITER_VERSION (F("0.3.1")) #define XMLWRITER_VERSION (F("0.3.2"))
// for comment() // for comment()
#define NOMULTILINE false #define NOMULTILINE false
#define MULTILINE true #define MULTILINE true
// for tagOpen(), tagEnd() // for tagOpen(), tagEnd()
#define NEWLINE true #define NEWLINE true
#define NONEWLINE false #define NONEWLINE false
#define NOINDENT false // for tagClose() #define NOINDENT false // for tagClose()
// for tagEnd() // for tagEnd()
#define SLASH true #define SLASH true
#define NOSLASH false #define NOSLASH false
// deepness of XML tree 5..10 // deepness of XML tree 5..10
// needed for stack of tagStack // needed for stack of tagStack
#ifndef XMLWRITER_MAXLEVEL #ifndef XMLWRITER_MAXLEVEL
#define XMLWRITER_MAXLEVEL 5 // adjust for deeper nested structures #define XMLWRITER_MAXLEVEL 5 // adjust for deeper nested structures
#endif #endif
#ifndef XMLWRITER_MAXTAGSIZE #ifndef XMLWRITER_MAXTAGSIZE
#define XMLWRITER_MAXTAGSIZE 15 // adjust for longer fields - !! eats memory !! #define XMLWRITER_MAXTAGSIZE 15 // adjust for longer fields - !! eats memory !!
#endif #endif
// reduce footprint by commenting next line // reduce footprint by commenting next line
#define XMLWRITER_ESCAPE_SUPPORT #define XMLWRITER_ESCAPE_SUPPORT
// configuration - setConfig // configuration - setConfig
#define XMLWRITER_NONE 0x00 #define XMLWRITER_NONE 0x00
#define XMLWRITER_COMMENT 0x01 #define XMLWRITER_COMMENT 0x01
#define XMLWRITER_INDENT 0x02 #define XMLWRITER_INDENT 0x02
#define XMLWRITER_NEWLINE 0x04 #define XMLWRITER_NEWLINE 0x04
// uncomment next line to reduce ~30bytes RAM in escape() (AVR oonly) // uncomment next line to reduce ~30bytes RAM in escape() (AVR oonly)
// #define __PROGMEM__ // #define __PROGMEM__

View File

@ -1,11 +1,10 @@
// //
// FILE: KMLWriterTest.ino // FILE: KMLWriterTest.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.3
// PURPOSE: simple KML writer // PURPOSE: simple KML writer
// DATE: 2015-05-21 // DATE: 2015-05-21
// URL: https://github.com/RobTillaart/XMLWriter // URL: https://github.com/RobTillaart/XMLWriter
//
#include <XMLWriter.h> #include <XMLWriter.h>
@ -96,3 +95,4 @@ This is a demo of the XMLWriter lib for Arduino
// -- END OF FILE -- // -- END OF FILE --

View File

@ -1,11 +1,9 @@
// //
// FILE: XMLWriterDefaultSerial.ino // FILE: XMLWriterDefaultSerial.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: make a simple XML generating lib // PURPOSE: make a simple XML generating lib
// DATE: 2020-04-24 // DATE: 2020-04-24
// URL: https://github.com/RobTillaart/XMLWriter // URL: https://github.com/RobTillaart/XMLWriter
//
#include <XMLWriter.h> #include <XMLWriter.h>
@ -133,3 +131,4 @@ void loop()
// -- END OF FILE -- // -- END OF FILE --

View File

@ -1,11 +1,10 @@
// //
// FILE: XMLWriterEthernet.ino // FILE: XMLWriterEthernet.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo XML writer for EthernetClient // PURPOSE: demo XML writer for EthernetClient
// DATE: 2020-04-24 // DATE: 2020-04-24
// URL: https://github.com/RobTillaart/XMLWriter // URL: https://github.com/RobTillaart/XMLWriter
//
#include <XMLWriter.h> #include <XMLWriter.h>

View File

@ -1,11 +1,9 @@
// //
// FILE: XMLWriterEthernet.ino // FILE: XMLWriterEthernet.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: demo XML writer for EthernetClient // PURPOSE: demo XML writer for EthernetClient
// DATE: 2020-04-24 // DATE: 2020-04-24
// URL: https://github.com/RobTillaart/XMLWriter // URL: https://github.com/RobTillaart/XMLWriter
//
#include <XMLWriter.h> #include <XMLWriter.h>

View File

@ -1,11 +1,10 @@
// //
// FILE: XMLWriterPrint_1.ino // FILE: XMLWriterPrint_1.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: demo Print interface // PURPOSE: demo Print interface
// DATE: 2020-07-07 // DATE: 2020-07-07
// URL: https://github.com/RobTillaart/XMLWriter // URL: https://github.com/RobTillaart/XMLWriter
//
#include <XMLWriter.h> #include <XMLWriter.h>
@ -24,7 +23,8 @@ void setup()
XML.comment("XMLWriter Print interface"); XML.comment("XMLWriter Print interface");
XML.setConfig(0); // no indent, no (further) comments XML.setConfig(0); // no indent, no (further) comments
// The {} are not mandatory shows the XML structure in the code... // The {} and indentations are not mandatory
// however they shows the XML structure in the code...
XML.tagOpen("Order"); XML.tagOpen("Order");
{ {

View File

@ -1,14 +1,12 @@
// //
// FILE: XMLWriterPrint_3.ino // FILE: XMLWriterPrint_3.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: demo Print interface - Printable data types // PURPOSE: demo Print interface - Printable data types
// DATE: 2020-07-07 // DATE: 2020-07-07
// URL: https://github.com/RobTillaart/XMLWriter // URL: https://github.com/RobTillaart/XMLWriter
// //
// example works for UNO but does not compile for ESP,
// example works for UNO but does not compile for ESP, // to investigate [complex vs Complex]
// to investigate [complex vs Complex]
#include <XMLWriter.h> #include <XMLWriter.h>
@ -47,3 +45,4 @@ void loop()
// -- END OF FILE -- // -- END OF FILE --

View File

@ -1,18 +1,16 @@
// //
// FILE: XMLWriterPrint_4.ino // FILE: XMLWriterPrint_4.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo Print interface - PROGMEM strings // PURPOSE: demo Print interface - PROGMEM strings
// DATE: 2020-07-07 // DATE: 2020-07-07
// URL: https://github.com/RobTillaart/XMLWriter // URL: https://github.com/RobTillaart/XMLWriter
//
#include <XMLWriter.h> #include <XMLWriter.h>
XMLWriter XML(&Serial); XMLWriter XML(&Serial);
#define NUMBERZ F("1.2.3.4.5") #define NUMBERZ (F("1.2.3.4.5"))
void setup() void setup()
@ -41,3 +39,4 @@ void loop()
// -- END OF FILE -- // -- END OF FILE --

View File

@ -1,24 +1,22 @@
// //
// FILE: XMLWriterSDcard.ino.ino // FILE: XMLWriterSDcard.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: XML writing to SD card // PURPOSE: XML writing to SD card
// DATE: 2020-04-24 // DATE: 2020-04-24
// URL: https://github.com/RobTillaart/XMLWriter // URL: https://github.com/RobTillaart/XMLWriter
// //
// Note: this application will write to the SD card immediately // Note: this application will write to the SD card immediately
// and it will append to the data.xml file every time started. // and it will append to the data.xml file every time started.
//
#include <SPI.h> #include <SPI.h>
#include <SD.h> #include <SD.h>
// SPI PINS // SPI PINS
// MOSI 11 // MOSI 11
// MISO 12 // MISO 12
// CLOCK 13 // CLOCK 13
// CS 10 // CS 10
#define CS 10 // adjust this ChipSelect line if needed ! #define CS 10 // adjust this ChipSelect line if needed !
#include <XMLWriter.h> #include <XMLWriter.h>

View File

@ -1,11 +1,10 @@
// //
// FILE: XMLWriterTest.ino // FILE: XMLWriterTest.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.6
// PURPOSE: make a simple XML generating lib // PURPOSE: make a simple XML generating lib
// DATE: 2013-11-06 // DATE: 2013-11-06
// URL: https://github.com/RobTillaart/XMLWriter // URL: https://github.com/RobTillaart/XMLWriter
//
#include <XMLWriter.h> #include <XMLWriter.h>

View File

@ -1,11 +1,10 @@
// //
// FILE: XMLWriterDemo01.ino // FILE: XMLWriterDemo01.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.3
// PURPOSE: XML writer demo // PURPOSE: XML writer demo
// DATE: 2016-03-16 // DATE: 2016-03-16
// URL: https://github.com/RobTillaart/XMLWriter // URL: https://github.com/RobTillaart/XMLWriter
//
#include <XMLWriter.h> #include <XMLWriter.h>
@ -106,3 +105,4 @@ void loop()
// -- END OF FILE -- // -- END OF FILE --

View File

@ -39,6 +39,8 @@ bytesWritten KEYWORD2
# Instances (KEYWORD2) # Instances (KEYWORD2)
# Constants (LITERAL1) # Constants (LITERAL1)
XMLWRITER_VERSION LITERAL1
NOMULTILINE LITERAL1 NOMULTILINE LITERAL1
MULTILINE LITERAL1 MULTILINE LITERAL1
NEWLINE LITERAL1 NEWLINE LITERAL1

View File

@ -15,8 +15,9 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/XMLWriter" "url": "https://github.com/RobTillaart/XMLWriter"
}, },
"version": "0.3.1", "version": "0.3.2",
"license": "MIT", "license": "MIT",
"frameworks": "arduino", "frameworks": "arduino",
"platforms": "*" "platforms": "*",
"headers": "XMLWriter.h"
} }

View File

@ -1,5 +1,5 @@
name=XMLWriter name=XMLWriter
version=0.3.1 version=0.3.2
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for creating XML sentence=Arduino library for creating XML

View File

@ -37,6 +37,7 @@
unittest_setup() unittest_setup()
{ {
fprintf(stderr, "XMLWRITER_VERSION: %s\n", (char *) XMLWRITER_VERSION);
} }
unittest_teardown() unittest_teardown()
@ -44,10 +45,30 @@ unittest_teardown()
} }
unittest(test_constants)
{
assertFalse(NOMULTILINE);
assertTrue(MULTILINE);
assertTrue(NEWLINE);
assertFalse(NONEWLINE);
assertFalse(NOINDENT);
assertTrue(SLASH);
assertFalse(NOSLASH);
assertEqual( 5, XMLWRITER_MAXLEVEL);
assertEqual(15, XMLWRITER_MAXTAGSIZE);
assertEqual(0x00, XMLWRITER_NONE );
assertEqual(0x01, XMLWRITER_COMMENT);
assertEqual(0x02, XMLWRITER_INDENT );
assertEqual(0x04, XMLWRITER_NEWLINE);
}
unittest(test_constructor) unittest(test_constructor)
{ {
fprintf(stderr, "VERSION: %s\n", XMLWRITER_VERSION);
XMLWriter XML(&Serial); XMLWriter XML(&Serial);
assertEqual(0, XML.bytesWritten()); assertEqual(0, XML.bytesWritten());
assertEqual(2, XML.getIndentSize()); assertEqual(2, XML.getIndentSize());
@ -59,8 +80,6 @@ unittest(test_constructor)
unittest(test_header_flush) unittest(test_header_flush)
{ {
fprintf(stderr, "VERSION: %s\n", XMLWRITER_VERSION);
XMLWriter XML(&Serial); XMLWriter XML(&Serial);
XML.header(); XML.header();