0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

VC++でXMLファイル操作

Posted at

はじめに

ベースはネイティブだったのですが、結局タイムアップでVC++ CLIで妥協してしまった...
最初の実装キーワードは持っているんだけど、うまくサイトが見つけられなかったんですよね。
次からはGPTに相談しながら対応してみようかな
(一応、さっきサイト調べ直してこれかぁ~と納得)

サンプルコード

VC++ CLIならそのまま動くのですが、ネイティブベースだと取得データを加工しないとダメだった
※参考サイトの

CppSettingFileOperation.cpp
#include "pch.h"
#include <iostream>

#include <tchar.h>

#using <mscorlib.dll>
#using <System.xml.dll>

using namespace System;
using namespace System::Xml;

void Write(XmlDocument^ doc, String^ target)
{
	XmlNodeList^ list = doc->GetElementsByTagName(target);

	Console::WriteLine(target);

	for each( XmlElement^ element in list )
	{
		Console::WriteLine(L"\t{0}", element->InnerText);
	}
}

int main()
{
    std::cout << "Hello World!\n";

	XmlDocument^ doc = gcnew XmlDocument();
	doc->Load(L"test.xml");

	Write(doc, L"名前");
}

vcxproj設定

image.png
image.png
※vcxprojファイル内の定義

CppSettingFileOperation.vcxproj
    <PostBuildEvent>
      <Command>copy $(ProjectDir)test.xml $(OutDir)</Command>
    </PostBuildEvent>

参考サイト

◆C++CLIでXDocumentでXML
 https://suzulang.com/ccli-xdocument-xml/
◆VC++でのXMLの読み込み
 https://dixq.net/forum/viewtopic.php?t=794
  ※この辺りを参考にCLIで対応してしまった。

◆Visual C++ で System::String から Char に変換する
 https://learn.microsoft.com/ja-jp/troubleshoot/developer/visualstudio/csharp/language-compilers/convert-systemstring-char
  ※変換周りとかも考慮しなくちゃいけないから大変だった...

◆プログラム備忘録 C++ での Xml パーサー
 https://ohwhsmm7.blog.fc2.com/blog-entry-441.html
◆C/C++のXML Parserについてよくまとまっているサイト - PIYO - Tech & Life -
 https://blog.piyo.tech/posts/2014-07-21-193000/
  ※これらのサイトで色々種類があることがわかった。

◆MSXML 6.0を使ってみた - Gobble up pudding
 https://gup.monster/entry/2014/02/28/005654
◆XmlLite プログラミング
 https://docs.solab.jp/xmllite/
  ※次はこのサイトベースで作成してみる...かな

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?