using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Xml;
public class ReadXml : MonoBehaviour {
Hashtable ht = new Hashtable();
string filePath = @"C:\Users\JohnLin\Desktop\CKIP\xmlcorpus_004.xml";
XmlDocument xmlDocument = new XmlDocument();
int sentenceLenght = 0;
private void Start() {
xmlDocument.Load(filePath);
XmlNodeList genre = xmlDocument.SelectNodes("//genre");
senterce();
}
///
///xml 句子
///
private void senterce (){
XmlNodeList topM = xmlDocument.SelectNodes("//text"); // 節點
foreach (XmlElement elements in topM)
{
while(true){
if(elements.GetElementsByTagName("sentence")[sentenceLenght] != null){ // sentence 節點
Debug.Log(elements.GetElementsByTagName("sentence")[sentenceLenght].InnerText);
break;
}
}
}
}
}
------- XML -------
<corpus>
<article>
<genre>散文</genre>
<style>記敘</style>
<mode>written</mode>
<topic>其他文學創作</topic>
<medium>視聽媒體</medium>
<author>
<name>周文仁</name>
<sex>男</sex>
<nationality>中華民國</nationality>
<nativelang>中文</nativelang>
</author>
<publisher />
<publishlocation />
<publishdate>1994</publishdate>
<edition />
<title />
<text>
<sentence>生活(Na) 不過(Cbb) 就(D) 是(SHI) 一個個(Neqa) 的(DE)
</text>
</article>
</corpus>
------結果圖------
沒有留言:
張貼留言