Merhaba arkadaşlar bu makalemizde C++ da Xml dosyasındaki
artist kısmındaki ilk veriyi textBox ta gösterimini sağlayacağız.
Şekil 1
Şekil 2
MyForm.h
#pragma once
#include <windows.h>
#using <System.dll>
#using <System.Xml.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
namespace cpptextboxxml {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Xml;
using namespace System::IO;
/// <summary>
/// Summary for MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: Add
the constructor code here
//
}
protected:
/// <summary>
/// Clean up any
resources being used.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TextBox^
textBox1;
private: System::Windows::Forms::Button^
button1;
protected:
private:
/// <summary>
/// Required designer
variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for
Designer support - do not modify
/// the contents of this
method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// textBox1
//
this->textBox1->Font = (gcnew
System::Drawing::Font(L"Arial
Narrow", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(162)));
this->textBox1->Location = System::Drawing::Point(0,
0);
this->textBox1->Multiline = true;
this->textBox1->Name = L"textBox1";
this->textBox1->ScrollBars =
System::Windows::Forms::ScrollBars::Vertical;
this->textBox1->Size = System::Drawing::Size(284, 266);
this->textBox1->TabIndex = 0;
//
// button1
//
this->button1->Font = (gcnew
System::Drawing::Font(L"Arial
Narrow", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(162)));
this->button1->Location = System::Drawing::Point(64,
275);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(138, 47);
this->button1->TabIndex = 1;
this->button1->Text = L"Get document";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6,
13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 331);
this->Controls->Add(this->button1);
this->Controls->Add(this->textBox1);
this->Name = L"MyForm";
this->Text = L"MyForm";
this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void button1_Click(System::Object^
sender,
System::EventArgs^ e)
{
String^ strFilename = L"catalog.xml";
XmlDocument^ docVideo = gcnew XmlDocument;
if (File::Exists(strFilename))
{
docVideo->Load(strFilename);
// Locate the
root node and
// get a
reference to its first child
//Kok dugumdeki ilk child node u
referans
//aliyoruz.
XmlNode^ node = docVideo->DocumentElement->FirstChild;
// Create a
list of the child nodes of
// the first
node under the root
//Kok dugumun altinda ilk dugumun
//bir child dugum listesi
olusturulur.
XmlNodeList^ list = node->ChildNodes;
// Visit each
node
// Her bir dugumu ziyaret et
for (int i = 0; i < list->Count; i++)
{
// Look for a
node named artist
// artist adinda bir dugum
aranir.
if (list[i]->Name == L"artist")
{
//
Once/if you find it,
//
1. Access its first child
//
2. Create a list of its child nodes
//Ilk olarak/o bulunursa
// 1. Onun ilk child
ina eris
// 2. Onun child
dugumlerinin bir
//listesini olustur.
XmlNodeList^ listTitle =
list[i]->ChildNodes;
//
Display the values of the nodes
// Dugum degerlerini
goruntule
for (int j = 0; j < listTitle->Count; j++)
textBox1->Text
= listTitle[j]->InnerText + "\r\n" + textBox1->Text;
}
}
}
else
MessageBox::Show(L"The
file " + strFilename + L" was not found");
}
private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^
e)
{
textBox1->Clear();
}
};
}
MyForm.cpp
#include "MyForm.h"
using namespace System;
using namespace System::Windows::Forms;
[STAThreadAttribute]
void Main(array<String^>^ args) {
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
cpptextboxxml::MyForm form;
Application::Run(% form);
}
Bir
makalenin daha sonuna geldik. Bir sonraki makalede görüşmek üzere. Bahadır
ŞAHİN
0 comments:
Yorum Gönder