2.1 Using Soul XML Libraries
2.1.1 Creating a Project
To create a project that uses the Soul XML library components:
-
Create a Soul-compatible project as described in this
document.
- Right-click the solution in the Solution Explorer and select 'Add | Existing Project...'
-
Navigate to the C:\soul-4.0.0\soul\ast
folder and add the ast.vcxproj
to the solution.
-
Do the same for
-
C:\soul-4.0.0\soul\common
,
-
C:\soul-4.0.0\soul\lex
,
-
C:\soul-4.0.0\soul\lexer
,
-
C:\soul-4.0.0\soul\parser
,
-
C:\soul-4.0.0\soul\token
,
-
C:\soul-4.0.0\util
,
-
C:\soul-4.0.0\soul\xml\dom
,
-
C:\soul-4.0.0\soul\xml\dom_parser
,
-
C:\soul-4.0.0\soul\xml\processor
,
-
C:\soul-4.0.0\soul\xml\xml_parser
and
-
C:\soul-4.0.0\soul\xml\xpath
projects.
2.1.2 Example
I have created an example program that uses the XML DOM parser and XPath components:
import std.core;
import util;
import soul.xml.dom;
import soul.xml.dom.parser;
import soul.xml.xpath;
int main()
{
try
{
util::Init();
std::unique_ptr<soul::xml::Document> doc = soul::xml::ParseXmlFile("C:/soul-4.0.0/soul/xml/xml_test_data/library.xml");
std::unique_ptr<soul::xml::xpath::NodeSet> nodeSet = soul::xml::xpath::EvaluateToNodeSet("//object/name", doc.get());
int n = nodeSet->Count();
for (int i = 0; i < n; ++i)
{
soul::xml::Node* node = nodeSet->GetNode(i);
if (node->IsElementNode())
{
soul::xml::Element* element = static_cast<soul::xml::Element*>(node);
std::cout << element->GetAttribute("value") << std::endl;
}
}
}
catch (const std::exception& ex)
{
std::cerr << ex.what() << std::endl;
return 1;
}
util::Done();
return 0;
}
2.1.3 Adding References
To add references to the required modules to your project:
- Expand your project in the Solution Explorer
- Right-click 'References' and select 'Add Reference...'
-
Add references to the following modules:
2.1.4 Adding Lexer Resource Files
To add required lexer resource files to your project:
- Right-click your project in the Solution Explorer
- Select 'Add | Existing Item...'
-
Navigate to the C:\soul-4.0.0\rc
folder and add the soul.xml.xpath.lexer.classmap.rc
file to your project.
2.1.5 Compiling the Solution
-
Select the 64 | Debug
configuration.
-
Select the Build | Build Solution
command.
- The required Soul libraries and then your project should compile successfully.
-
Select the 64 | Release
configuration
-
Select the Build | Build Solution
command.
- The required Soul libraries and then your project should compile successfully.