本文整理汇总了C++中XmlDocument类的典型用法代码示例。如果您正苦于以下问题:C++ XmlDocument类的具体用法?C++ XmlDocument怎么用?C++ XmlDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XmlDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SaveAnswer
void AnswerGenerator::SaveAnswer( AnswerList & answerList )
{
XmlDocument xmlDoc;
XmlNode * resNode = xmlDoc.AddNode( "resource" );
int count = answerList.size();
for( int num = 0; num < count; num++ )
{
AnswerData & answer = answerList[ num ];
std::string ans = answer._answer;
std::string ref = answer._reference;
XmlNode * qsNode = resNode->AddNode( "question" );
char buf[8]; itoa(num, buf, 10);
qsNode->SetAttribute( "no", buf );
XmlNode * referenceNode = qsNode->AddNode( "table" );
referenceNode->SetText( ref.c_str(), XmlNode::NUMBER );
XmlNode * answerNode = qsNode->AddNode( "answer" );
answerNode->SetText( ans.c_str(), XmlNode::NUMBER );
}
std::string path = "./resource/ResultAnswer.xml";
xmlDoc.SaveFile( path.c_str() );
}
示例2: image
//==============================================================================
Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
{
Drawable* result = 0;
Image image (ImageFileFormat::loadFrom (data, (int) numBytes));
if (image.isValid())
{
DrawableImage* const di = new DrawableImage();
di->setImage (image);
result = di;
}
else
{
const String asString (String::createStringFromData (data, (int) numBytes));
XmlDocument doc (asString);
ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
if (outer != 0 && outer->hasTagName ("svg"))
{
ScopedPointer <XmlElement> svg (doc.getDocumentElement());
if (svg != 0)
result = Drawable::createFromSVG (*svg);
}
}
return result;
}
示例3: ParseStream
/**
* @brief
* Parse incoming stream data
*/
void InputStream::ParseStream(const String &sStream)
{
// Has the document been initialized yet?
if (!m_pStream) {
// Parse beginning of document
m_cXml.Parse(sStream.GetASCII());
// Get root element
XmlElement *pRoot = m_cXml.GetRootElement();
if (pRoot && pRoot->GetValue() == "stream:stream") {
// Save stream element
m_pStream = pRoot;
// Callback function for stream element
m_pJabberConnection->OnStreamStarted(*m_pStream);
}
} else {
// Parse XML part
XmlDocument cXml;
cXml.Parse(sStream.GetASCII());
XmlElement *pRoot = cXml.GetRootElement();
if (pRoot) {
// Add element
XmlElement *pElement = static_cast<XmlElement*>(pRoot->Clone());
m_pStream->LinkEndChild(*pElement);
// Callback function for element
m_pJabberConnection->OnElement(*pElement);
}
}
}
示例4: TransformNodeToObject
bool CXmlDocument::TransformNodeToObject(CXmlDocument*pNode,CXmlDocument*pOutDOM)
{
XmlDocument pXmlDoc;
HRESULT hr = pXmlDoc.CreateInstance(__uuidof(MSXML2::DOMDocument));
if ( hr == S_OK )
{
CComQIPtr<IDispatch> pDisp = pXmlDoc;
if ( !pDisp ) return false;
CComVariant vOut;
vOut.vt = VT_DISPATCH;
vOut.pdispVal = pDisp.Detach();
hr = m_pDoc->transformNodeToObject(pNode->m_pDoc,vOut);
if ( hr == S_OK )
{
bool bLogin=false;
hr = pOutDOM->SetXmlDocument(&vOut,bLogin);
return true;
}
}
return false;
}
示例5: httpOutcome
XmlOutcome AWSXMLClient::MakeRequest(const Aws::String& uri,
const Aws::AmazonWebServiceRequest& request,
Http::HttpMethod method) const
{
HttpResponseOutcome httpOutcome(BASECLASS::AttemptExhaustively(uri, request, method));
if (!httpOutcome.IsSuccess())
{
return XmlOutcome(httpOutcome.GetError());
}
if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0)
{
XmlDocument xmlDoc = XmlDocument::CreateFromXmlStream(httpOutcome.GetResult()->GetResponseBody());
if (!xmlDoc.WasParseSuccessful())
{
AWS_LOG_ERROR(LOG_TAG, "Xml parsing for error failed with message %s", xmlDoc.GetErrorMessage().c_str());
return AWSError<CoreErrors>(CoreErrors::UNKNOWN, "Xml Parse Error", xmlDoc.GetErrorMessage(), false);
}
return XmlOutcome(AmazonWebServiceResult<XmlDocument>(std::move(xmlDoc),
httpOutcome.GetResult()->GetHeaders(), httpOutcome.GetResult()->GetResponseCode()));
}
return XmlOutcome(AmazonWebServiceResult<XmlDocument>(XmlDocument(), httpOutcome.GetResult()->GetHeaders()));
}
示例6: myDocument
String BirdID::returnSpeciesName(int predictedClass)
{
XmlDocument myDocument (File ("C:/Users/Aneesh/Desktop/BirdID_Data/species.xml"));
ScopedPointer<XmlElement> element = myDocument.getDocumentElement();
XmlElement* speciesElement = element->getChildElement(0);
int numSpecies = speciesElement->getAllSubText().getIntValue();
speciesElement = element->getChildElement(1);
String speciesText = speciesElement->getAllSubText();
int startIndex = 0;
String tempString;
for(int i=0;i<numSpecies;i++)
{
int endIndex = speciesText.indexOfChar(startIndex+1,',');
if(i==predictedClass-1)
{
tempString = speciesText.substring(startIndex,endIndex);
break;
}
startIndex = endIndex+1;
}
element = nullptr;
return tempString;
}
示例7: uri
void DbXmlUpdateFactory::applyPut(const PendingUpdate &update, DynamicContext *context)
{
DbXmlUri uri(update.getValue().first()->
asString(context), true);
if (uri.isDbXmlScheme()) {
const DbXmlNodeImpl *content =
(const DbXmlNodeImpl*)update.getTarget().get();
string cname = uri.getContainerName();
string docname = uri.getDocumentName();
DbXmlConfiguration *conf = GET_CONFIGURATION(context);
XmlManager &mgr = conf->getManager();
XmlContainer cont = ((Manager&)mgr).getOpenContainer(cname);
if (cont.isNull()) {
string msg = "Target container for fn:put -- ";
msg += cname;
msg += " -- must be open";
throw XmlException(XmlException::INVALID_VALUE,
msg);
}
OperationContext &oc = conf->getOperationContext();
XmlDocument doc = mgr.createDocument();
doc.setName(docname);
XmlEventReader *reader =
(XmlEventReader*)content->getEventReader(context);
DBXML_ASSERT(reader);
doc.setContentAsEventReader(*reader);
XmlUpdateContext uc = mgr.createUpdateContext();
// use internal interface to avoid additional transaction
int err = ((Container &)cont).addDocumentInternal(oc.txn(), doc, uc, 0);
if (err != 0)
throw XmlException(err);
}
}
示例8: previouslySavedEvents
//==============================================================================
void ProjucerAnalyticsDestination::saveUnloggedEvents (const std::deque<AnalyticsEvent>& eventsToSave)
{
XmlDocument previouslySavedEvents (savedEventsFile);
std::unique_ptr<XmlElement> xml (previouslySavedEvents.getDocumentElement());
if (xml.get() == nullptr || xml->getTagName() != "events")
xml.reset (new XmlElement ("events"));
for (auto& event : eventsToSave)
{
auto* xmlEvent = new XmlElement ("google_analytics_event");
xmlEvent->setAttribute ("name", event.name);
xmlEvent->setAttribute ("type", event.eventType);
xmlEvent->setAttribute ("timestamp", (int) event.timestamp);
xmlEvent->setAttribute ("user_id", event.userID);
auto* parameters = new XmlElement ("parameters");
for (auto& key : event.parameters.getAllKeys())
parameters->setAttribute (key, event.parameters[key]);
xmlEvent->addChildElement (parameters);
auto* userProperties = new XmlElement ("user_properties");
for (auto& key : event.userProperties.getAllKeys())
userProperties->setAttribute (key, event.userProperties[key]);
xmlEvent->addChildElement (userProperties);
xml->addChildElement (xmlEvent);
}
xml->writeToFile (savedEventsFile, {});
}
示例9: Exception
void
MyScene1::loadSceneFile(const char *filePath)
{
// load XML scene file
XmlDocument doc;
doc.fromFile(File::getPath(filePath));
// make sure the root element is named correctly
const XmlElement *root = doc.getRootElement();
if(root->getName() != "dromescene")
throw Exception("MyScene1::loadSceneFile(): Invalid root element name");
vector < RefPtr <Texture> > textures;
// loop through each child element
for(unsigned int i = 0; i < root->getNumChildren(); ++i) {
const XmlElement *child = root->getChild(i);
if(child->getName() == "texture") {
// create texture
const XmlAttribute *attr = child->getAttribute("filePath");
if(!attr)
throw Exception("MyScene1::loadSceneFile(): Texture without filePath");
textures.push_back(Texture::create(Image::create(attr->getValue())));
} else if(child->getName() == "block") {
// parse position
const XmlAttribute *attr = child->getAttribute("position");
if(!attr)
throw Exception("MyScene1::loadSceneFile(): Block without position");
Vector3 position(attr->getValue());
// parse bounds
attr = child->getAttribute("bounds");
if(!attr)
throw Exception("MyScene1::loadSceneFile(): Block without bounds");
Vector3 bounds(attr->getValue());
// parse texture index
attr = child->getAttribute("textureIndex");
unsigned int index = (attr != NULL) ? (unsigned int)String(attr->getValue()).toInt() : 0;
if(index >= textures.size())
throw Exception("MyScene1::loadSceneFile(): Block with invalid texture index");
// parse normalmap index
RefPtr <Texture> normalmap;
attr = child->getAttribute("normalmapIndex");
if(attr != NULL) {
unsigned int tmp = (unsigned int)String(attr->getValue()).toInt();
if(tmp >= textures.size())
throw Exception("MyScene1::loadSceneFile(): Block with invalid normalmap index");
normalmap = textures[tmp];
}
// create block
m_sceneObjects.push_back(new Block(position, bounds, textures[index], normalmap));
} else {
throw Exception("MyScene1::loadSceneFile(): Invalid element name '" + child->getName() + "'");
}
}
}
示例10: Save
bool Save()
{
std::ostringstream o;
o << "<agenda>" << std::endl;
o << "<notes>" << std::endl;
for (int i=0; i<(int)events.size(); i++) {
struct agenda_t *t = events[i];
o << "<event day=\"" << t->day << "\" month=\"" << t->month << "\" year=\"" << t->year << "\">" << std::endl;
o << t->event << std::endl;
o << "</event>" << std::endl;
}
o << "</notes>" << std::endl;
o << "</agenda>" << std::endl;
XmlDocument doc;
doc.Parse(o.str().c_str());
if (doc.Error()) {
return false;
}
doc.SaveFile(_file.c_str());
return true;
}
示例11: Save
/**
* @brief
* Saves the material
*/
bool PLSceneMaterial::Save(const String &sApplicationDrive, const String &sApplicationDir)
{
// Create XML document
XmlDocument cDocument;
// Add declaration
XmlDeclaration *pDeclaration = new XmlDeclaration("1.0", "ISO-8859-1", "");
cDocument.LinkEndChild(*pDeclaration);
// Add material
XmlElement *pMaterialElement = new XmlElement("Material");
pMaterialElement->SetAttribute("Version", "1");
// Save the parameters
SaveParameters(*pMaterialElement);
// Link material element
cDocument.LinkEndChild(*pMaterialElement);
// Get the absolute material filename
const String sFilename = sApplicationDrive + sApplicationDir + PLTools::GetResourceFilename(PLTools::ResourceMaterial, m_sName);
{ // Before we safe, we need to ensure that the target directory is there, else 'Save()' will fail!
Url cUrl = sFilename;
Directory cDirectory(cUrl.CutFilename());
cDirectory.CreateRecursive();
}
// Save settings
cDocument.Save(sFilename);
// Done
return true;
}
示例12: Initialise
void MaterialManager::Initialise(char *materialXMLFile)
{
// read through the xml file and load all materials
XmlDocument doc;
doc.Load(materialXMLFile);
TiXmlHandle * hdoc = doc.Handle();
TiXmlElement * root = hdoc->FirstChildElement().Element();
TiXmlElement * child = root->FirstChildElement();
// loop through our materials
while(child)
{
// get the name of the material
const char * matName = XmlUtilities::ReadAttributeAsString(child, "", "name");
// create the new material
Material* mat = new Material(matName);
mat->ReadXml(child); // read the properties
m_materialMap[matName] = mat; // add to the material map
// move to the next material
child = child->NextSiblingElement();
}
}
示例13: dict
//==============================================================================
void Material::load(const CString& filename, ResourceInitializer& init)
{
try
{
m_vars = std::move(ResourceVector<MaterialVariable*>(init.m_alloc));
Dictionary<MaterialVariable*> dict(10,
Dictionary<MaterialVariable*>::hasher(),
Dictionary<MaterialVariable*>::key_equal(),
init.m_alloc);
m_varDict = std::move(dict);
m_progs =
std::move(ResourceVector<ProgramResourcePointer>(init.m_alloc));
m_pplines =
std::move(ResourceVector<GlProgramPipelineHandle>(init.m_alloc));
XmlDocument doc;
doc.loadFile(filename, init.m_tempAlloc);
parseMaterialTag(doc.getChildElement("material"), init);
}
catch(std::exception& e)
{
throw ANKI_EXCEPTION("Failed to load material") << e;
}
}
示例14: XmlDocument
void XmlParser::readConfig()
{
XmlDocument* xmlConfigDoc = new XmlDocument(File(File::getCurrentWorkingDirectory().getChildFile(configFile)));
XmlElement* xmlConfigElem = xmlConfigDoc->getDocumentElement();
if (xmlConfigElem != NULL)
{
XmlElement* pictures = xmlConfigElem->getChildByName(T("pictures"));
if (pictures != NULL)
{
if (pictures->hasAttribute(T("path")))
{
m_picturePath = pictures->getStringAttribute(T("path"));
}
else
{
LOG_ERROR(T("Element \"pictures\" is incomplete"));
}
}
else
{
LOG_ERROR(T("Element \"pictures\" not found"));
}
delete xmlConfigElem;
}
else
{
LOG_ERROR((T("XML load failed: %ls"), (const juce_wchar*)xmlConfigDoc->getLastParseError()));
}
delete xmlConfigDoc;
}
示例15: SerializePayload
Aws::String UpdateTrafficPolicyInstanceRequest::SerializePayload() const
{
XmlDocument payloadDoc = XmlDocument::CreateWithRootNode("UpdateTrafficPolicyInstanceRequest");
XmlNode parentNode = payloadDoc.GetRootElement();
parentNode.SetAttributeValue("xmlns", "https://route53.amazonaws.com/doc/2013-04-01/");
Aws::StringStream ss;
if(m_tTLHasBeenSet)
{
XmlNode tTLNode = parentNode.CreateChildElement("TTL");
ss << m_tTL;
tTLNode.SetText(ss.str());
ss.str("");
}
if(m_trafficPolicyIdHasBeenSet)
{
XmlNode trafficPolicyIdNode = parentNode.CreateChildElement("TrafficPolicyId");
trafficPolicyIdNode.SetText(m_trafficPolicyId);
}
if(m_trafficPolicyVersionHasBeenSet)
{
XmlNode trafficPolicyVersionNode = parentNode.CreateChildElement("TrafficPolicyVersion");
ss << m_trafficPolicyVersion;
trafficPolicyVersionNode.SetText(ss.str());
ss.str("");
}
return payloadDoc.ConvertToString();
}