本文整理汇总了C++中DOMDocument::getElementById方法的典型用法代码示例。如果您正苦于以下问题:C++ DOMDocument::getElementById方法的具体用法?C++ DOMDocument::getElementById怎么用?C++ DOMDocument::getElementById使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMDocument
的用法示例。
在下文中一共展示了DOMDocument::getElementById方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: source
/**
* Canonicalize XML node using one of the supported methods in XML-DSIG
* Using Xerces for parsing XML to preserve the white spaces "as is" and get
* the same digest value on XML node each time.
*
* @param calc digest calculator implementation.
* @param ns signature tag namespace.
* @param tagName signature tag name.
*/
vector<unsigned char> SignatureBES::calcDigestOnNode(Digest* calc, const string& ns,
const string& tagName, const string &id) const
{
try
{
// Parse Xerces DOM from file, to preserve the white spaces "as is"
// and get the same digest value on XML node.
// Canonical XML 1.0 specification (http://www.w3.org/TR/2001/REC-xml-c14n-20010315)
// needs all the white spaces from XML file "as is", otherwise the digests won't match.
// Therefore we have to use Xerces to parse the XML file each time a digest needs to be
// calculated on a XML node. If you are parsing XML files with a parser that doesn't
// preserve the white spaces you are DOOMED!
// Initialize Xerces parser.
auto_ptr<XercesDOMParser> parser(new XercesDOMParser());
parser->setDoNamespaces(true);
parser->setValidationScheme(XercesDOMParser::Val_Always);
parser->setDoSchema(true);
parser->setCreateEntityReferenceNodes(false);
//ErrorHandler* errorHandler = /*(ErrorHandler*)*/ new HandlerBase();
//parser->setErrorHandler(errorHandler);
// Parse and return a copy of the Xerces DOM tree.
// Save to file an parse it again, to make XML Canonicalization work
// correctly as expected by the Canonical XML 1.0 specification.
// Hope, the next Canonical XMl specification fixes the white spaces preserving "bug".
stringstream ofs;
saveToXml(ofs);
string data = ofs.str();
MemBufInputSource source((XMLByte*)data.c_str(), data.size(), "temp");
parser->parse(source);
DOMDocument *dom = parser->getDocument();
DOMNode *node = 0;
// Select node, on which the digest is calculated.
if(id.empty())
{
XMLCh *tagNs = XMLString::transcode(ns.c_str());
XMLCh *tag = XMLString::transcode(tagName.c_str());
DOMNodeList* nodeList = dom->getElementsByTagNameNS(tagNs, tag);
if(nodeList->getLength() == 1)
node = nodeList->item(0);
XMLString::release(&tagNs);
XMLString::release(&tag);
}
else
{
XMLCh *tagId = XMLString::transcode(id.c_str());
node = dom->getElementById(tagId);
XMLString::release(&tagId);
}
// Make sure that exactly one node was found.
if(!node)
THROW_SIGNATUREEXCEPTION("Could not find '%s' node which is in '%s' namespace in signature XML.", tagName.c_str(), ns.c_str());
// Canocalize XML using one of the three methods supported by XML-DSIG
XSECC14n20010315 canonicalizer(dom, node);
canonicalizer.setCommentsProcessing(false);
canonicalizer.setUseNamespaceStack(true);
// Find the method identifier
SignedInfoType& signedInfo = signature->signedInfo();
CanonicalizationMethodType& canonMethod = signedInfo.canonicalizationMethod();
CanonicalizationMethodType::AlgorithmType& algorithmType = canonMethod.algorithm();
DEBUG("C14N ns(%s) tagName(%s) algorithmType(%s)", ns.c_str(), tagName.c_str(), algorithmType.c_str());
// Set processing flags according to algorithm type.
if(algorithmType == URI_ID_C14N_NOC) {
// Default behaviour, nothing needs to be changed
} else if(algorithmType == URI_ID_C14N_COM) {
canonicalizer.setCommentsProcessing(true);
} else if(algorithmType == URI_ID_EXC_C14N_NOC) {
// Exclusive mode needs to include xml-dsig in root element
// in order to maintain compatibility with existing implementations
canonicalizer.setExclusive();
} else if(algorithmType == URI_ID_EXC_C14N_COM) {
canonicalizer.setExclusive();
canonicalizer.setCommentsProcessing(true);
#ifdef URI_ID_C14N11_NOC
} else if(algorithmType == URI_ID_C14N11_NOC) {
canonicalizer.setInclusive11();
} else if(algorithmType == URI_ID_C14N11_COM) {
canonicalizer.setInclusive11();
canonicalizer.setCommentsProcessing(true);
#endif
} else {
// Unknown algorithm.
THROW_SIGNATUREEXCEPTION("Unsupported SignedInfo canonicalization method '%s'", algorithmType.c_str());
}
//.........这里部分代码省略.........