XMLUnit for C++ - c++

Does anyone know if there exists something like XMLUnit for C++? I'm looking for an easy way to check nodes, values, etc in a XML output. We are using Google test in Visual Studio but I suppose any library that makes the work easier will be enough.
I'm using Xerces as an XML parser but XMLUnit (http://xmlunit.sourceforge.net/) has some features wrapped over the XML parser that are very useful for unit testing. For example, asserts using XPath expressions, functions to compare two "similar" XMLs, etc.

I have used a combination of Xerces and CPPUnit to accomplish this in the past. In my test cases I would create a DOM object with the Xerces API in the setUp() function. This DOM would represent my expected results. In the test case itself I would then read the XML file and the class under test would populate a DOM object representing the contents of the file. To check equality I would walk through the two DOM trees via the Xerces API (DOMTreeWalker) and use CPPUnit assertions as I compared the contents of the DOM nodes. It was a bit tedious but there were no frameworks available at the time that could mimic XmlUnit. I would imagine that Google Test would work just as well as CPPUnit for accomplishing this task.
The Xerces API has some support for XPath expressions:
http://xerces.apache.org/xerces-c/faq-parse-3.html#faq-2
For validation you would need to set up an error handler as mentioned here and incorporate it into your test case:
Validating document in Xerces C++
For XSLT transform checking you would need to use Xalan. It works with Xerces so I wouldn't anticipate any major difficulties:
http://xalan.apache.org/old/xalan-c/index.html
I was not able to locate any obvious products that packaged XMLUnit-like operations in C++. So the answer is I think you will have to roll your own. Good luck.

I really like http://pugixml.org/
It:
is stable
is extremely fast
has great documentation and sample code
is licensed under the MIT license
is very STL friendly
is still quite an active project
has great support for xpath

You can use tinyxml package here: tinyxml
I'm working with it and it's quite friendly and bug free.
It's an xml handling.
I guess it wasn't designed for unit testing, but you can use it to check/test your xml files.
It as expected loads the xml into a DOM object and supplies a nice API to run on the nodes.
Gal

Xerces at http://xerces.apache.org/xerces-c/i pretty full featured, has a C++ interface and produces good error messages, which several other XML parsers don't do so well. Having said that, it's pretty big & I've wound up using my own wrapper round the C parser Expat.

I'm currently using libxml++ for a personal project of mine.

I use Boost property_tree for xml, easy to use, pretty robust and works well with Boost unit test framework.

Related

Should I use XML in my c++ game

Is XML something required to use in modern games? Sense I'm trying to make game that will be programmed like a professional programmer did it, So should i use XML in my game or it is just an optional thing, Why and Why not?
There's nothing wrong with using XML if it solves your problem. There's nothing wrong with not using XML if it isn't the best option for solving your problem.
If you want to store data in an a format which is easy to query, then XML is not a bad option. If you're look for space efficiency, XML is not a good option. If you are looking for cross-platform features, XML is a no-brainer compared to binary formats.
JSON is another option which is very simple and very lightweight.
In short, it depends on your requirements. If you want more direction you'll have to give more information.
Use whatever works for you. Don't judge your tools based on whether something is considered "uncool". If it works for you and helps you create maintainable and flexible code and data, use it.
Now specifically for XML - that's definitely a format that is widely used and has libraries for virtually every platform. I've worked on a recent Xbox 360 and PlayStation 3 title that made use of XML.

Implementing a DSL with (subset) functionality of XSLT

My requirements are that I provide a way for Business Analyst-types to specify XSLT-like transformations without the complexity of XSLT or XPath. Basically there are incoming XML documents and the client needs to be able to specify situations where elements/subtrees should be edited/removed/replaced/added. It will essentially be a rules engine for applying XSL transformations.
My first approach was to come up with a DSL using an ANTLR grammar to parse into Java code but I get the feeling I'm overlooking the KISS approach. I've scoured the web but haven't been able to find any existing libraries/frameworks for providing a simple interface for applying transformations. I feel like I'm missing the obvious solution but can't put my finger on it.
Have you looked at Altova MapForce?

C++ tool to generate random XML files from XML Schema?

I think there should be a tool to do so ? is anyone here aware of any ?
I saw other posts related to this but found none for C++, I am aware that I can do that with JAVA and C#.
If you use XML Spy or oXygen, you can generate sample XML files based on a schema. Both tools accept commandline options and can be run in batch mode so that'll probably fit in your unit tests, if that's what you're after. Wrap your own C++ code around it and you're in business.
If you need quality XML, with tons of tweakable options, you might want to check out http://www.code-generator.com/XML-Sample-Generator.aspx. No C++ here, just a tool that works, and rises beyond the default "lorem ipsum..." output.
HTH,
~Rob

Are there any XSL Lint tools?

I'm looking for an XSL lint tool which is actively maintained. The only one I can find is this one, but the last update was in 2000 (9 years old!). Any help would be great!
Phillip,
Creating a good lint for xlst is quite hard, because validity of xslt templates depends on the parser that is used. Each parser has it own extensions.
For example java's xalan can be easily extended with custom xpath functions, which are obviously coded in java. Because of that any .net validator will fail to validate advance xalan's xslts.
So first of all you need to know what processor you are going to use. If you use java based processors I recommend to use Eclipse which can validate the templates on the fly.
I've tired two eclipse plugins, It is worth mentioning that both support debugging and xslt/xpath code completion:
Oxygen XML editor - a commercial (~$300) XML/XSLT editor/eclipse plugin.
It can use the following engines: Xalan, Saxon, Xsltproc,
It is able to check:
correctness of xsl:template
correctness of name attribute of xsl:call-template
duplicated definition of xslt variables
validity of dtd's
validity of xslt header
validity of xml namespaces
validity of XPath
validity of xsl:value-of if an xml is associated to xslt
correctness of xsl:import for local and remote files (it support xml catalogs)
I must say that the plugin is really good but on the other hand it isn't open source.
XSLT Project - an open source plugin (it is part of Eclipse Web Tools Platform).
It is quite young (started in September 2008), however it has very active community. Currently it supports only Xalan and JAXP.
It detects the following errors and warnings:
invalid xslt header
incorrect dtd
incorrect imports (it handle only relative imports, xml catalogs are planed for version
1.1)
The above list is definitely incomplete because lack of support for xml catalogs made this project unusable for me.
Yes, look at this one, published Dec. 2008:
http://lists.xml.org/archives/xml-dev/200812/msg00178.html
You should look for "XSL profiler" or "XSL debugger". There are dozens of these.

Unit Testing XQuery

I've been working with a document repository using XQuery (via Java and .NET interfaces) and was wondering if anyone has any recommendations for unit testing XQuery modules?
There are several XQuery unit testing frameworks, but most are special-purpose written for a specific XQuery Processor. This is not a complete list, but includes most of the popular ones I'm aware of:
MarkLogic
Roxy Unit Tester https://github.com/marklogic/roxy/wiki/Unit-Testing
XQUT https://github.com/mblakele/xqut
xray https://github.com/robwhitby/xray
eXist
XQSuite http://exist-db.org/exist/apps/doc/xqsuite.xml
BaseX
XQuery Unit Module http://docs.basex.org/wiki/Unit_Module
Here is a quick DIY type solution for this problem:
Poor man's unit testing with XQuery (dead link).
This approach seems to have been embraced and extended for the tests of the xprocxq project.
Other tools exist, for example XTC.
This link may spruce your development. This is just an idea but you can develope and enhance more on this with various unit-test case design ideas.
since Xml is a king in meta-data world its quite easy to design and run.
design a Test-Case Xml by having all details capture
test-data ( input & expected result )
test-case id
test-case local methods
invoke dynamically based on the details.
functions
sample test script
results
Try XQSuite
It's pretty slick; here's the "minimal example":
declare namespace test="http://exist-db.org/xquery/xqsuite";
declare function %test:assertEquals("Hello world") local:hello() {
"Hello world"
};
Additionally, XSpec works wonderfully for XSLT testing (provides nicely formatted HTML test results, for example) BUT appears to need a bit of work with XQuery testing. The project appears to have become inactive in the past few years.