|
TXMLDocument 한번도 써번적 없는데..
덕분에 함 써보네요
저도 처음이라 잘 모릅니다만
아래와 같이 하니 원하는 값을 얻을수 있더군요
도움이 되길 기대합니다.
void __fastcall TForm1::Button2Click(TObject *Sender)
{
AnsiString xmlFile = "<?xml version='1.0' encoding='utf-8'?>";
xmlFile += "<interface>";
xmlFile += "<version>1.0</version>";
xmlFile += "<interface_name>Check</interface_name>";
xmlFile += "<results count='1'>";
xmlFile += "<result>";
xmlFile += "<product type='String'>test</product>";
xmlFile += "<getcount type='int'>0</getcount>";
xmlFile += "</result>";
xmlFile += "</results>";
xmlFile += "</interface>";
XMLDocument1->LoadFromXML(xmlFile);
_di_IXMLNode RootNode=XMLDocument1->DocumentElement;
_di_IXMLNode RsltNodes=RootNode->ChildNodes->FindNode("results");
_di_IXMLNode RsltNode=RsltNodes->ChildNodes->FindNode("result");
_di_IXMLNode FNode1=RsltNode->ChildNodes->FindNode("product");
_di_IXMLNode FNode2=RsltNode->ChildNodes->FindNode("getcount");
ShowMessage("product: "+FNode1->Text);
ShowMessage("product type: "+FNode1->Attributes["type"]);
ShowMessage("getcount: "+FNode2->Text);
ShowMessage("getcount type: "+FNode2->Attributes["type"]);
}
//---------------------------------------------------------------------------
음..
_di_IXMLNode RootNode=XMLDocument1->DocumentElement;
_di_IXMLNode RsltNodes=RootNode->ChildNodes->FindNode("results");
_di_IXMLNode RsltNode=RsltNodes->ChildNodes->FindNode("result");
위 3줄을 아래와 같이 1줄로 줄여도 되겠네요
_di_IXMLNode RsltNode=XMLDocument1->DocumentElement->ChildNodes->FindNode("results")->ChildNodes->FindNode("result");
//---------------------------------------------------------------
[xml 데이타가 file로 저장되어있다면 ]
void __fastcall TForm1::Button4Click(TObject *Sender)
{
XMLDocument1->LoadFromFile("C:\\Test.xml"); //그냥 이렇게 읽어오면 되네요
_di_IXMLNode RootNode=XMLDocument1->DocumentElement;
_di_IXMLNode RsltNodes=RootNode->ChildNodes->FindNode("results");
_di_IXMLNode RsltNode=RsltNodes->ChildNodes->FindNode("result");
_di_IXMLNode FNode1=RsltNode->ChildNodes->FindNode("product");
_di_IXMLNode FNode2=RsltNode->ChildNodes->FindNode("getcount");
ShowMessage("product: "+FNode1->Text);
ShowMessage("product type: "+FNode1->Attributes["type"]);
ShowMessage("getcount: "+FNode2->Text);
ShowMessage("getcount type: "+FNode2->Attributes["type"]);
}
//---------------------------------------------------------------------------
그럼..
김관옥 님이 쓰신 글 :
: 안녕하세요~!
: TXMLDocument 콤포넌트를 사용할 일이 있어 사용해 봤는데.. 어찌 된일인지 안되네요.. ㅠㅠ
:
: 소스는 다음과 같이 하였습니다.
:
: xmlFile = "<?xml version='1.0' encoding='utf-8'?>";
: xmlFile += "<interface>";
: xmlFile += "<version>1.0</version>";
: xmlFile += "<interface_name>Check</interface_name>";
: xmlFile += "<results count='1'>";
: xmlFile += "<result>";
: xmlFile += "<product type='String'>test</product>";
: xmlFile += "<getcount type='int'>0</getcount>";
: xmlFile += "</result>";
: xmlFile += "</results>";
: xmlFile += "</interface>";
:
: XML 데이타가 위처럼 있을 경우 results 에 포함되여 있는 count 의 갯수 만큼
: result 값에 있는 product , getcount 의 값을 받고 싶은데 .. 어떻게 해야 하나요..
:
: 이런저런 방법을 써봤는데.. 하는것 마다 안되네요..
: 고수님들 꼭 좀 가르쳐 주세요~! 어제부터 지금 까지 삽질하면서.. 이것저것 해봤는데.. 어떻게 해야할지 모르겠네요
: 고수님들 부탁드립니다.
|