TinyXML2 is a simple, small, efficient, C++ XML parser that can be easily integrated into other programs.

Related tags

XML tinyxml2
Overview

TinyXML-2

TravisCI Status AppVeyor Status

C/C++ CI Unixish

TinyXML-2 Logo

TinyXML-2 is a simple, small, efficient, C++ XML parser that can be easily integrated into other programs.

The master is hosted on github: https://github.com/leethomason/tinyxml2

The online HTML version of these docs: http://leethomason.github.io/tinyxml2/

Examples are in the "related pages" tab of the HTML docs.

What it does.

In brief, TinyXML-2 parses an XML document, and builds from that a Document Object Model (DOM) that can be read, modified, and saved.

XML stands for "eXtensible Markup Language." It is a general purpose human and machine readable markup language to describe arbitrary data. All those random file formats created to store application data can all be replaced with XML. One parser for everything.

http://en.wikipedia.org/wiki/XML

There are different ways to access and interact with XML data. TinyXML-2 uses a Document Object Model (DOM), meaning the XML data is parsed into a C++ objects that can be browsed and manipulated, and then written to disk or another output stream. You can also construct an XML document from scratch with C++ objects and write this to disk or another output stream. You can even use TinyXML-2 to stream XML programmatically from code without creating a document first.

TinyXML-2 is designed to be easy and fast to learn. It is one header and one cpp file. Simply add these to your project and off you go. There is an example file - xmltest.cpp - to get you started.

TinyXML-2 is released under the ZLib license, so you can use it in open source or commercial code. The details of the license are at the top of every source file.

TinyXML-2 attempts to be a flexible parser, but with truly correct and compliant XML output. TinyXML-2 should compile on any reasonably C++ compliant system. It does not rely on exceptions, RTTI, or the STL.

What it doesn't do.

TinyXML-2 doesn't parse or use DTDs (Document Type Definitions) or XSLs (eXtensible Stylesheet Language.) There are other parsers out there that are much more fully featured. But they are generally bigger and more difficult to use. If you are working with browsers or have more complete XML needs, TinyXML-2 is not the parser for you.

TinyXML-1 vs. TinyXML-2

TinyXML-2 is now the focus of all development, well tested, and your best choice between the two APIs. At this point, unless you are maintaining legacy code, you should choose TinyXML-2.

TinyXML-2 uses a similar API to TinyXML-1 and the same rich test cases. But the implementation of the parser is completely re-written to make it more appropriate for use in a game. It uses less memory, is faster, and uses far fewer memory allocations.

TinyXML-2 has no requirement or support for STL. By returning const char* TinyXML-2 can be much more efficient with memory usage. (TinyXML-1 did support and use STL, but consumed much more memory for the DOM representation.)

Features

Code Page

TinyXML-2 uses UTF-8 exclusively when interpreting XML. All XML is assumed to be UTF-8.

Filenames for loading / saving are passed unchanged to the underlying OS.

Memory Model

An XMLDocument is a C++ object like any other, that can be on the stack, or new'd and deleted on the heap.

However, any sub-node of the Document, XMLElement, XMLText, etc, can only be created by calling the appropriate XMLDocument::NewElement, NewText, etc. method. Although you have pointers to these objects, they are still owned by the Document. When the Document is deleted, so are all the nodes it contains.

White Space

Whitespace Preservation (default)

Microsoft has an excellent article on white space: http://msdn.microsoft.com/en-us/library/ms256097.aspx

By default, TinyXML-2 preserves white space in a (hopefully) sane way that is almost compliant with the spec. (TinyXML-1 used a completely different model, much more similar to 'collapse', below.)

As a first step, all newlines / carriage-returns / line-feeds are normalized to a line-feed character, as required by the XML spec.

White space in text is preserved. For example:

<element> Hello,  World</element>

The leading space before the "Hello" and the double space after the comma are preserved. Line-feeds are preserved, as in this example:

<element> Hello again,
          World</element>

However, white space between elements is not preserved. Although not strictly compliant, tracking and reporting inter-element space is awkward, and not normally valuable. TinyXML-2 sees these as the same XML:

<document>
	<data>1</data>
	<data>2</data>
	<data>3</data>
</document>

<document><data>1</data><data>2</data><data>3</data></document>

Whitespace Collapse

For some applications, it is preferable to collapse whitespace. Collapsing whitespace gives you "HTML-like" behavior, which is sometimes more suitable for hand typed documents.

TinyXML-2 supports this with the 'whitespace' parameter to the XMLDocument constructor. (The default is to preserve whitespace, as described above.)

However, you may also use COLLAPSE_WHITESPACE, which will:

  • Remove leading and trailing whitespace
  • Convert newlines and line-feeds into a space character
  • Collapse a run of any number of space characters into a single space character

Note that (currently) there is a performance impact for using COLLAPSE_WHITESPACE. It essentially causes the XML to be parsed twice.

Error Reporting

TinyXML-2 reports the line number of any errors in an XML document that cannot be parsed correctly. In addition, all nodes (elements, declarations, text, comments etc.) and attributes have a line number recorded as they are parsed. This allows an application that performs additional validation of the parsed XML document (e.g. application-implemented DTD validation) to report line number information for error messages.

Entities

TinyXML-2 recognizes the pre-defined "character entities", meaning special characters. Namely:

&amp;	&
&lt;	<
&gt;	>
&quot;	"
&apos;	'

These are recognized when the XML document is read, and translated to their UTF-8 equivalents. For instance, text with the XML of:

Far &amp; Away

will have the Value() of "Far & Away" when queried from the XMLText object, and will be written back to the XML stream/file as an ampersand.

Additionally, any character can be specified by its Unicode code point: The syntax &#xA0; or &#160; are both to the non-breaking space character. This is called a 'numeric character reference'. Any numeric character reference that isn't one of the special entities above, will be read, but written as a regular code point. The output is correct, but the entity syntax isn't preserved.

Printing

Print to file

You can directly use the convenience function:

XMLDocument doc;
...
doc.SaveFile( "foo.xml" );

Or the XMLPrinter class:

XMLPrinter printer( fp );
doc.Print( &printer );

Print to memory

Printing to memory is supported by the XMLPrinter.

XMLPrinter printer;
doc.Print( &printer );
// printer.CStr() has a const char* to the XML

Print without an XMLDocument

When loading, an XML parser is very useful. However, sometimes when saving, it just gets in the way. The code is often set up for streaming, and constructing the DOM is just overhead.

The Printer supports the streaming case. The following code prints out a trivially simple XML file without ever creating an XML document.

XMLPrinter printer( fp );
printer.OpenElement( "foo" );
printer.PushAttribute( "foo", "bar" );
printer.CloseElement();

Examples

Load and parse an XML file.

/* ------ Example 1: Load and parse an XML file. ---- */
{
	XMLDocument doc;
	doc.LoadFile( "dream.xml" );
}

Lookup information.

/* ------ Example 2: Lookup information. ---- */
{
	XMLDocument doc;
	doc.LoadFile( "dream.xml" );

	// Structure of the XML file:
	// - Element "PLAY"      the root Element, which is the
	//                       FirstChildElement of the Document
	// - - Element "TITLE"   child of the root PLAY Element
	// - - - Text            child of the TITLE Element

	// Navigate to the title, using the convenience function,
	// with a dangerous lack of error checking.
	const char* title = doc.FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" )->GetText();
	printf( "Name of play (1): %s\n", title );

	// Text is just another Node to TinyXML-2. The more
	// general way to get to the XMLText:
	XMLText* textNode = doc.FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" )->FirstChild()->ToText();
	title = textNode->Value();
	printf( "Name of play (2): %s\n", title );
}

Using and Installing

There are 2 files in TinyXML-2:

  • tinyxml2.cpp
  • tinyxml2.h

And additionally a test file:

  • xmltest.cpp

Simply compile and run. There is a visual studio 2019 project included, a simple Makefile, an Xcode project, a Code::Blocks project, a cmake CMakeLists.txt, and a meson.build are included to help you. The top of tinyxml.h even has a simple g++ command line if you are using Unix/Linux/BSD and don't want to use a build system.

Using as a Meson Subproject

Create a wrap file such as:

[wrap-git]
url = https://github.com/leethomason/tinyxml2.git
revision = 8.0.1  # this can be any commit-ish (tag, sha) or the special value `head`

or, if you prefer to not use git

[wrap-file]
directory = tinyxml2-8.0.1  # this is the name of the directory after de-compressing
source_url = https://github.com/leethomason/tinyxml2/archive/8.0.1.tar.gz
source_hash = sha256sum of compressed sources

in your project's subprojects/ folder, and follow the meson documentation for using fallbacks.

Building TinyXML-2 - Using vcpkg

You can download and install TinyXML-2 using the vcpkg dependency manager:

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install tinyxml2

The TinyXML-2 port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.

Versioning

TinyXML-2 uses semantic versioning. http://semver.org/ Releases are now tagged in github.

Note that the major version will (probably) change fairly rapidly. API changes are fairly common.

Documentation

The documentation is built with Doxygen, using the 'dox' configuration file.

License

TinyXML-2 is released under the zlib license:

This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.

Contributors

Thanks very much to everyone who sends suggestions, bugs, ideas, and encouragement. It all helps, and makes this project fun.

The original TinyXML-1 has many contributors, who all deserve thanks in shaping what is a very successful library. Extra thanks to Yves Berquin and Andrew Ellerton who were key contributors.

TinyXML-2 grew from that effort. Lee Thomason is the original author of TinyXML-2 (and TinyXML-1) but TinyXML-2 has been and is being improved by many contributors.

Thanks to John Mackay at http://john.mackay.rosalilastudio.com for the TinyXML-2 logo!

Comments
  • Overhaul CMake build

    Overhaul CMake build

    This PR overhauls the CMake build to use modern CMake best practices. It bumps the minimum version to 3.15, which is available essentially everywhere. Ubuntu 20.04 LTS includes 3.16. Meanwhile, Visual Studio 2019 and Homebrew both provide newer versions still.

    The installed package honors a few different ways of switching the tinyxml2::tinyxml2 alias between static and shared. If the user specifies static or shared as a component to find_package, it will use those (or fail). Otherwise, if tinyxml2_SHARED_LIBS is set, it will use that value to determine which to use (or fail). Otherwise, it will decay to standard CMake behavior, using BUILD_SHARED_LIBS as a hint. For more detail, see my blog post on distributing both shared and static libs in CMake.

    I added GitHub Actions testing to build tinyxml2 as static/shared and debug/release. It runs the tests on all four configurations, both as part of the main build and through find_package, to ensure that it doesn't rot. Since the GHA testing covers both Travis and AppVeyor, I removed those files.

    I removed support for Biicode, which has been dead for six years. Its website's SSL certificates have expired and some of the links on its GitHub repo now point to spam. Direct those users (if any remain) to vcpkg instead.

    Fixes #804


    If users want a single configuration of tinyxml2, it suffices to run:

    $ cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=YES
    $ cmake --build build
    $ cmake --install build --prefix /path/to/install
    

    Then their own build files don't need to be any more complicated than this:

    cmake_minimum_required(VERSION 3.16)
    project(example)
    
    find_package(tinyxml2 REQUIRED)
    
    add_executable(main main.cpp)
    target_link_libraries(main PRIVATE tinyxml2::tinyxml2)
    

    To build it, they would run:

    $ cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/path/to/install
    $ cmake --build build
    

    I think it would be good to evaluate whether continuing to support seven (!) build systems is worthwhile. They aren't being tested rigorously by CI, so there's a looming threat of bit-rotting. CMake being a de-facto standard should put it in the running for being the primary build system. At the very least, if the other build systems are maintained by the community, the community should contribute GitHub Actions workflows.

    For reference:

    1. CMake
    2. premake5
    3. Meson (compatible with CMake)
    4. Code::Blocks (can be generated by CMake)
    5. GNU Make (can be generated by CMake)
    6. Xcode (can be generated by CMake)
    7. Visual Studio (can be generated by CMake)

    Because the source tree layout is so constrained by so many build systems, I had to awkwardly reference xmltest.cpp via directory traversal from test/CMakeLists.txt. Moving it (and resources) into the test folder would clean things up a bit, but I intentionally only touched CMake-related things in this PR.

    opened by alexreinking 29
  • heap-buffer-overflow Error In tinyxml2.cpp:2286::strlen()

    heap-buffer-overflow Error In tinyxml2.cpp:2286::strlen()

    hello!I use libfuzzer to test XMLDocument::parse().then I meet heap-buffer-overflow Error.I think it is due to tinyxml2.cpp:2286 strlen().because function strlen() lead to heap-buffer-overflow.

    opened by EnchantedJohn 27
  • Row/column of current element / error?

    Row/column of current element / error?

    In TinyXML1 it was possible to query the row/column of the currrent element (e.g. in case of an error). This was very nice to show a descriptive error message so the user was able to pinpoint the error easily. Even it was possible to open an editor and jumping to that element.

    I see that in TinyXML2 the Row() and Column() methods are gone. Will the return or is there an alternative / better way to obtain that information?

    Note that the error must not be an XML error, but may come from a user-defined validation. So the element might be XML correct, but the content may be wrong for the application.

    enhancement 
    opened by MortenMacFly 18
  • Installed tinyxml2-config.cmake confuses library detection

    Installed tinyxml2-config.cmake confuses library detection

    Currently, installed file tinyxml2-config.cmake after call to CMake's find_package leads to variable <PackageName>_FOUND being set, but no <PackageName>_LIB* or other expected variables are set. As a result it would lead to the library not being used (see my comment on PR 3897 for cppcheck). Should not this file be complemented to set at lest <PackageName>_LIBRARIES variable?

    opened by gdsotirov 14
  • Problem opening files

    Problem opening files

    I am now getting a few users saying they are getting a file not found error when my application reads a XML file (using this library).

    I have had a look at this method:

    static FILE* callfopen( const char* filepath, const char* mode )
    {
        TIXMLASSERT( filepath );
        TIXMLASSERT( mode );
    #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
        FILE* fp = 0;
        errno_t err = fopen_s( &fp, filepath, mode );
        if ( err ) {
            return 0;
        }
    #else
        FILE* fp = fopen( filepath, mode );
    #endif
        return fp;
    }
    

    I have noticed that if there is a error with the fopen_s call that we lose the actual error number.

    I have changed it like this:

    XMLError XMLDocument::LoadFile( const char* filename )
    {
        Clear();
    int iErrorCode = 0;
        FILE* fp = callfopen( filename, "rb", &iErrorCode );
    
        if ( !fp ) {
            if (iErrorCode == ENOENT)
                SetError( XML_ERROR_FILE_NOT_FOUND, filename, 0 );
            else
            {
                char *sErrorNo = new char(15);
                XMLUtil::ToStr(iErrorCode, sErrorNo, 15);
                SetError(XML_ERROR_FILE_COULD_NOT_BE_OPENED, filename, sErrorNo);
                delete sErrorNo;
            }
    
            return _errorID;
        }
        LoadFile( fp );
        fclose( fp );
        return _errorID;
    }
    

    I don't know if it is the best way. But at least I can get at error number now.

    opened by ajtruckle 14
  • msvc 2003 fails compilation

    msvc 2003 fails compilation

    I have the old msvc 2003 toolkit and when perfoming the following commands: $ cmake -DCMAKE_INSTALL_PREFIX=c:/usr ..

    -- Building for: NMake Makefiles -- The C compiler identification is MSVC 13.10.3077 -- The CXX compiler identification is MSVC 13.10.3077 -- Check for working C compiler: C:/Archivos de programa/Microsoft Visual Studio .NET 2003/Vc7/bin/cl.exe -- Check for working C compiler: C:/Archivos de programa/Microsoft Visual Studio .NET 2003/Vc7/bin/cl.exe -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler: C:/Archivos de programa/Microsoft Visual Studio .NET 2003/Vc7/bin/cl.exe -- Check for working CXX compiler: C:/Archivos de programa/Microsoft Visual Studio .NET 2003/Vc7/bin/cl.exe -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done -- Generating done -- Build files have been written to: C:/foe/builds/tinyxml2-master/build

    $ nmake

    C:\foe\builds\tinyxml2-master\tinyxml2.cpp(455) : error C3861: 'snprintf': no se encontró el identificador, ni siquiera con búsqueda dependiente de argumentos

    it seems that my compiler doesn't support snprintf or vsnprintf....any workarounds?

    opened by aullidolunar 14
  • Heap overflow when parsing an XML file (segmentation fault)

    Heap overflow when parsing an XML file (segmentation fault)

    Hello,

    You can check the segmentation fault using the following file: (this could be dangerous in scenarios that we are reading an untrusted XML file from a malicious actor)

    #include "tinyxml2.h"
    
    int main(int argc, char* argv[])
    {
        tinyxml2::XMLDocument doc;
        doc.Parse((const char *)0xdeadbeaf);
        return 0;
    }
    

    Also, this is the result of the Exploitable plugin of GDB:

    Description: Access violation on source operand
    Short description: SourceAv (19/22)
    Hash: e00e77ccffc576e5c04edbeb2a57f0a1.e00e77ccffc576e5c04edbeb2a57f0a1
    Exploitability Classification: UNKNOWN
    Explanation: The target crashed on an access violation at an address matching the source operand of the current instruction. This likely indicates a read access violation.
    Other tags: AccessViolation (21/22)
    
    
    opened by imanoracle 13
  • tinyxml2 collapse elements with space as text

    tinyxml2 collapse elements with space as text

    I use tinyxml2 to process svg files, which is xml-like. Here is an example of valid svg file:

    <svg xmlns="http://www.w3.org/2000/svg" width="128" height="128">
      <text> </text>
    </svg>
    

    But after resaving file with tinyxml2, I get:

    <svg xmlns="http://www.w3.org/2000/svg" width="128" height="128">
      <text/>
    </svg>
    

    How can I prevent it?

    bug 
    opened by RazrFalcon 13
  • fix sidenote on issue #588

    fix sidenote on issue #588

    This fixes the namespace sidenote in issue #588. After this change, the way to link to tinyxml2 in cmake will become

    target_link_libraries(${PROJECT_NAME} tinyxml2::tinyxml2)
    
    opened by jasjuang 12
  • Is the boolean value in the xml configurable?

    Is the boolean value in the xml configurable?

    I now use the latest build of tinyxml2 and it is writing boolean values as true/false.

    This breaks my XSL scripts that were doing tests with 0 and 1.

    Is it a configurable setting or do I have to change my XSL scripts?

    opened by ajtruckle 12
  • Building with Borland C++ Builder 6 - 2

    Building with Borland C++ Builder 6 - 2

    The second issue is less obvious to fix. I get the following error when compiling:

    [C++ Error] tinyxml2.cpp(1930): E2451 Undefined symbol 'value'

    I'm not really a template wizard, so I have no clue how to fix this...

    opened by wvvelzen 12
  • bug for private XMLElement constructor

    bug for private XMLElement constructor

    Hi,

    I have a construct like std::unique_ptr mRoot;

    So here is always a compile error with Visual Studio and GCC. I seems this is not a good idea to have the constructor private.

    /usr/include/c++/10/bits/unique_ptr.h: In instantiation of ‘void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = tinyxml2::XMLElement]’: /usr/include/c++/10/bits/unique_ptr.h:182:16: required from ‘void std::__uniq_ptr_impl<_Tp, _Dp>::reset(std::__uniq_ptr_impl<_Tp, _Dp>::pointer) [with _Tp = tinyxml2::XMLElement; _Dp = std::default_deletetinyxml2::XMLElement; std::__uniq_ptr_impl<_Tp, _Dp>::pointer = tinyxml2::XMLElement*]’ /usr/include/c++/10/bits/unique_ptr.h:456:12: required from ‘void std::unique_ptr<_Tp, _Dp>::reset(std::unique_ptr<_Tp, _Dp>::pointer) [with _Tp = tinyxml2::XMLElement; _Dp = std::default_deletetinyxml2::XMLElement; std::unique_ptr<_Tp, _Dp>::pointer = tinyxml2::XMLElement*]’ /usr/include/c++/10/bits/unique_ptr.h:85:2: error: ‘virtual tinyxml2::XMLElement::~XMLElement()’ is private within this context 85 | delete __ptr; | ^~~~~~~~~~~~

    regards elli

    opened by elli-one 0
  • add FirstDescendantElement and LastDescendantElement functions

    add FirstDescendantElement and LastDescendantElement functions

    The normal way to find a descendent is FirstChildElement()->FirstChildElement() But it lacks the null check, so I added the 2 functions to cover the null check.

    The last string of the list should be null, and an empty string in the list matches any child, example: static const char* names[] = { "son", "grandson", nullptr }; FirstDescendantElement(names);

    static const char* names[] = { "", "level2", nullptr }; FirstDescendantElement(names);

    opened by sunnyqeen 0
  • 在系统语言为繁体中文情况下,读取中文不正常

    在系统语言为繁体中文情况下,读取中文不正常

    1.在系统语言为繁体中文情况下异常,但在系统语言为简体中文情况正常 2.我的vs项目使用的UNIcode字符集 3.下面是我写的代码,但无论如何转字符编码(我有尝试过gb2312 utf8 ansi),变量str都无法正确解析字符串,均为乱码 tinyxml2::XMLDocument doc;

    XMLDeclaration* declaration = doc.NewDeclaration();
    
    string text = "白白魂";
    //ANSItoUTF8(text);
    
    XMLElement* pRoot = doc.NewElement("Root");
    
    pRoot->SetText(text.c_str());
    doc.InsertFirstChild(declaration);
    doc.InsertEndChild(pRoot);
    doc.SaveFile("C:\\Users\\Method-PC\\Desktop\\1.xml");
    
    
    tinyxml2::XMLDocument loaddoc;
    loaddoc.LoadFile("C:\\Users\\Method-PC\\Desktop\\1.xml");
    XMLElement *ele =  loaddoc.RootElement();
    string str  = ele->GetText();
    //UTF8toANSI(str);
    int a = 0
    

    企业微信截图_20220810160112 ;

    opened by MethodJiao 0
  • Improvement: Detect self reference on 'Insert...'

    Improvement: Detect self reference on 'Insert...'

    Hi there,

    today I managed to produce a stupid error by copy&pasting.

    Here is the minimal code snipplet:

    // <foo> auto *pElement = xmlDoc.NewElement("foo"); pElement->InsertEndChild( pElement ); /\ |__ this should have been some other parent element

    The problems with the construct is that it compiles and appears to run fine until the xmlDoc is destroyed. Then some assertions in the clean up code are triggered. Now I could see that there was a problem, but it took me some hours to understand (and finally see) what the problem was.

    I suggest to add an assertion that the pointer handed to 'InsertChildElement()' is != this What do you think?

    Best regards, Sven

    opened by Lorandil 0
  • fopen_s on Windows doesn't allow for concurrent read-only access of files

    fopen_s on Windows doesn't allow for concurrent read-only access of files

    What's happening:

    On Windows, and for specific versions of MSVC, the following code is used to open files: (see lines 2290-2297 in tinyxml2.cpp):

    #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
        
    FILE* fp = 0;
        
    const errno_t err = fopen_s( &fp, filepath, mode );
        if ( err ) {
            return 0;
        }
    #else
        FILE* fp = fopen( filepath, mode );
    

    It would seem that this code was added to avoid a warning using MSVC, as using fopen does indeed result in a warning on MSVC14, with the warning message suggesting to use fopen_s instead.

    According to the Microsoft API entry for fopen_s, however, (see the remarks section in https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fopen-s-wfopen-s?view=msvc-170), fopen_s does not open files while allowing for file sharing.

    This means that a multithreaded or multiprocess program opening a file using tinyxml will occasionally fail to obtain file access if another thread or process currently has that file open, even in read-only mode.

    To avoid this issue, and also compile without a warning, I have used Microsoft's recommended alternative for file sharing, _fsopen for the Windows only case (this requres including Share.h at the beginning of the file, using the same #define that enables this code to be ran):

     FILE* fp = 0;
     fp = _fsopen(filename, mode, _SH_DENYNO);
     if (fp)
         return fp;
      return 0;
    
    

    The downside to this function is that it does not return a descriptive error code as fopen_s does, however the error code wasn't used outside of the scope of this function, so perhaps that is alright, perhaps not. I have not observed any issues while using this alternative, but of course I may have missed one or more.

    opened by andres-a-salas 0
  • undefined reference to `tinyxml2::XMLDocument::LoadFile(char const*)'

    undefined reference to `tinyxml2::XMLDocument::LoadFile(char const*)'

    Hello, I am running the xmltest.cpp on visual studio code 2022. I got the error listed below. The compiler is g++ version 7.5.0. I tried to install older version on the device(Ubuntu 20.04). However Ubuntu 20.04 doesn't support older versions. I am wondering how could be solved?

    /tinyxml2-master/xmltest.cpp:67: undefined reference to tinyxml2::XMLDocument::ErrorIDToName(tinyxml2::XMLError)' /tinyxml2-master/xmltest.cpp:67: undefined reference totinyxml2::XMLDocument::ErrorIDToName(tinyxml2::XMLError)' /tinyxml2-master/xmltest.cpp:117: undefined reference to tinyxml2::XMLDocument::XMLDocument(bool, tinyxml2::Whitespace)' /tinyxml2-master/xmltest.cpp:118: undefined reference totinyxml2::XMLDocument::LoadFile(char const*)' Thanks

    opened by Jirra2020 0
Owner
Lee Thomason
Lee Thomason
pugixml is a Light-weight, simple and fast XML parser for C++ with XPath support

pugixml is a C++ XML processing library, which consists of a DOM-like interface with rich traversal/modification capabilities, an extremely fast XML parser which constructs the DOM tree from an XML file/buffer, and an XPath 1.0 implementation for complex data-driven tree queries. Full Unicode support is also available, with Unicode interface variants and conversions between different Unicode encodings (which happen automatically during parsing/saving).

Arseny Kapoulkine 3.2k Oct 1, 2022
Tiny XML library.

Mini-XML Version 3.2 Mini-XML is a small XML parsing library that you can use to read XML data files or strings in your application without requiring

Michael R Sweet 357 Sep 25, 2022
Expat - a C library for parsing XML

Fast streaming XML parser written in C

Expat development team 793 Sep 25, 2022
A library to serialize custom classes to and from XML by adding a very minimal amount of code to a class.

ai-xml submodule This repository is a git submodule providing a C++ framework for serializing classes to and from XML with a minimal amount of code pe

Carlo Wood 2 Oct 1, 2022
Lee Thomason 296 Sep 10, 2022
BLLIP reranking parser (also known as Charniak-Johnson parser, Charniak parser, Brown reranking parser) See http://pypi.python.org/pypi/bllipparser/ for Python module.

BLLIP Reranking Parser Copyright Mark Johnson, Eugene Charniak, 24th November 2005 --- August 2006 We request acknowledgement in any publications that

Brown Laboratory for Linguistic Information Processing 214 Aug 15, 2022
BLLIP reranking parser (also known as Charniak-Johnson parser, Charniak parser, Brown reranking parser)

BLLIP reranking parser (also known as Charniak-Johnson parser, Charniak parser, Brown reranking parser)

Brown Laboratory for Linguistic Information Processing 214 Aug 15, 2022
C XML Minimalistic Library (CXML) - An XML library for C with a focus on simplicity and ease of use.

cxml (C XML Minimalistic Library) is a powerful and flexible XML library for C with a focus on simplicity and ease of use, coupled with features that enables quick processing of XML documents.

null 28 Feb 11, 2022
C library designed for the TI MSP432P401R microprocessor and the TI Educational Booster Pack, to easily play and control songs with the integrated Piezo Buzzer.

MusicLib C library designed for the TI MSP432P401R microprocessor and the TI Educational Booster Pack, to easily play and control songs with the integ

Matteo Merler 1 Nov 24, 2021
pugixml is a Light-weight, simple and fast XML parser for C++ with XPath support

pugixml is a C++ XML processing library, which consists of a DOM-like interface with rich traversal/modification capabilities, an extremely fast XML parser which constructs the DOM tree from an XML file/buffer, and an XPath 1.0 implementation for complex data-driven tree queries. Full Unicode support is also available, with Unicode interface variants and conversions between different Unicode encodings (which happen automatically during parsing/saving).

Arseny Kapoulkine 3.2k Oct 1, 2022
A small utility to embed files into C or C++ programs.

hexembed hexembed is a very small utility to help embed files in C or C++ programs in an easy, cross-platform way. Usage > gcc hexembed.c -o hexembed

Lewis Van Winkle 31 Jul 27, 2022
The Gecko SDK (GSDK) combines all Silicon Labs 32-bit IoT product software development kits (SDKs) based on Gecko Platform into a single, integrated SDK.

Silicon Labs Gecko SDK (GSDK) The Gecko SDK (GSDK) combines Silicon Labs wireless software development kits (SDKs) and Gecko Platform into a single, i

Silicon Labs 123 Sep 20, 2022
LANDrop is a cross-platform tool that you can use to conveniently transfer photos, videos, and other types of files to other devices on the same local network.

LANDrop is a cross-platform tool that you can use to conveniently transfer photos, videos, and other types of files to other devices on the same local network.

LANDrop 3.1k Oct 6, 2022
A small C library for building user interfaces with C, XML and CSS

LCUI A small C library for building user interfaces with C, XML and CSS. Table of contents Table of contents Introduction Features Screenshots Related

Liu 3.8k Sep 30, 2022
C.impl is a small portable C interpreter integrated with a line text editor

C.impl C.impl is a small portable C interpreter integrated with a line text editor, originally developed for the ELLO 1A computer: http://ello.cc The

KnivD 20 Sep 25, 2022
The pico can be used to program other devices. Raspberry pi made such an effort. However there is no board yet, that is open-source and can be used with OpenOCD as a general-purpose programmer

pico-probe-programmer The pico can be used to program other devices. Raspberry pi made such an effort. However there is no board yet, that is open-sou

martijn 21 Jul 20, 2022
An MQTT-based Virtual Wall for ESP8266 Devices and Gerber files to make the IR hat; this code and board can easily be adapted to be ANY infrared controller/remote!

Roomba-Virtual-Wall-ESP8266-MQTT An MQTT-based Virtual Wall for ESP8266 Devices I made this based off of the IRSend, IRremoteESP8266, and EspMQTTClien

null 8 Sep 20, 2021