xmlsq  0.9.0
Public Types | Static Public Member Functions | List of all members
xmlsq::Query Class Reference

Perform simple and full XPath 1.0 queries on an XML document. More...

Public Types

enum  Opts : unsigned int { None = 0x0 , Asciify = 0x1000 , Raw = 0x2000 , Trim = 0x4000 }
 

Static Public Member Functions

static std::string GetText (const std::string &xmlFile, const std::string &query, Opts opts=Opts::None)
 Extract text from the first matching XML file node. More...
 
static std::string FullQuery (const std::string &xmlFile, const std::string &query, Opts opts=Opts::None)
 Perform a full XPath query on the XML input. More...
 
static int Count (const std::string &xmlFile, const std::string &query)
 Compute the count for the XPath query. More...
 

Detailed Description

Perform simple and full XPath 1.0 queries on an XML document.

Member Enumeration Documentation

◆ Opts

enum xmlsq::Query::Opts : unsigned int
Enumerator
None 

Use default options.

Asciify 

Asciify the output as XML character references [default=UTF-8-encoded].

Raw 

Output nodeset in raw format [default=prettify].

Trim 

Trim leading and trailing whitespace (and collapse whitespace for an attribute value).

Member Function Documentation

◆ Count()

static int xmlsq::Query::Count ( const std::string &  xmlFile,
const std::string &  query 
)
static

Compute the count for the XPath query.

Parameters
xmlFileName of XML file or string containing XML data.
queryXPath 1.0 expression to select a node. This must evaluate to a node or node set.
Returns
The integer value of count(query).
Exceptions
std::runtime_errorif missing file or invalid XML or invalid XPath.
Remarks
int n = xmlsq::Query::Count("<a><b>abc</b><b>xyz</b></a>", "//b"); // 2
static int Count(const std::string &xmlFile, const std::string &query)
Compute the count for the XPath query.

◆ FullQuery()

static std::string xmlsq::Query::FullQuery ( const std::string &  xmlFile,
const std::string &  query,
Opts  opts = Opts::None 
)
static

Perform a full XPath query on the XML input.

Parameters
xmlFileName of XML file or string containing XML data.
queryXPath 1.0 expression.
optsFormatting options for output.
Returns
String containing result of query.
Exceptions
std::runtime_errorif missing file or invalid XML or invalid XPath.
Remarks
std::string s = xmlsq::Query::FullQuery("<a><b>abc</b><b>xyz</b></a>", "//b", xmlsq::Query::Raw); // <b>abc</b><b>xyz</b>
@ Raw
Output nodeset in raw format [default=prettify].
Definition: xmlsq.hpp:74
static std::string FullQuery(const std::string &xmlFile, const std::string &query, Opts opts=Opts::None)
Perform a full XPath query on the XML input.

◆ GetText()

static std::string xmlsq::Query::GetText ( const std::string &  xmlFile,
const std::string &  query,
Opts  opts = Opts::None 
)
static

Extract text from the first matching XML file node.

Parameters
xmlFileName of XML file or string containing XML data.
queryXPath 1.0 expression to select a node. This must evaluate to a node or node set.
optsFormatting options for output.
Returns
Extracted text.
Exceptions
std::runtime_errorif missing file or invalid XML or invalid XPath.
Remarks
std::string s = xmlsq::Query::GetText("<a><b>abc</b><b>xyz</b></a>", "//b"); // abc
static std::string GetText(const std::string &xmlFile, const std::string &query, Opts opts=Opts::None)
Extract text from the first matching XML file node.
Copyright © 2020-21 D.I. Management Services Pty Limited ABN 78 083 210 584 Australia. All rights reserved. <www.di-mgt.com.au> <www.cryptosys.net>. Generated on Fri Jul 16 2021 17:26:17 by Doxygen 1.9.1.