很简单,这种就是引用动态链接库
[DllImport("kernel32.dll")]
private static extern int CreateFile(
string lpFileName,
uint dwDesiredAccess,
int dwShareMode,
int lpSecurityAttributes,
int dwCreationDisposition,
int dwFlagsAndAttributes,
int hTemplateFile
);
这个就是引用"kernel32.dll"中的CreateFile函数,引入后就可以随便用啦,下面就是Open() ,Write(),Close(),返回布尔值,全部功能在class LPTControl 这个类中,需要使用时实例化这个类的对象,就可以调用了,有问题可以再问
先添加一个根节点,要不然xml文档是错误的,就不能读取了。
代码如下:
XmlDocument xmlDoc = new XmlDocument();
void readXml()
{
//加载xml文件, 假设你的xml文件名是xmlFile.xml
xmlDoc.Load(@"xmlFile.xml");
//得到根节点
XmlNode root = xmlDoc.DocumentElement;
//定义一个ArrayList,用来存放图片的名称
ArrayList imgName = new ArrayList();
//得到根节点下的所有albums节点
for (int i = 0; i < root.SelectNodes("albums").Count; i++)
{
//遍历每个albums节点下的所有photoset节点
for (int j = 0; i < root.SelectNodes("albums")[i].SelectNodes("photeset").Count; j++)
{
//遍历每个photoset下的photo节点
for (int k = 0; k < root.SelectNodes("albums")[i].SelectNodes("photeset")[j].SelectNodes("photo").Count; k++)
{
XmlNode imgNameNode = root.SelectNodes("albums")[i].SelectNodes("photeset")[j].SelectNodes("photo")[k].SelectSingleNode("pimage");
//得到属性名为src的属性值
string strName = imgNameNode.Attributes["src"].Value;
imgName.Add(strName);
}
}
}
}
调用的系统API,百度一下要使用的方法就能找到答案了