将图像插入xml文件中的文件夹和路径 [英] insert images to folder and path in xml file
本文介绍了将图像插入xml文件中的文件夹和路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在一个asp.net应用程序中工作,该应用程序处理将图像插入文件夹和xml文件的路径.以便它们在图库中可见.我有xml文件.我需要将数据动态输入到xml文件中
< pre lang =" > < 照片 >
< 照片 =" imgs/img 1.jpg" 链接URL =" >
< 标题 > hi1 < /title >
< de 脚本 ion > Demo < 脚本 >
< /photo >
< /photos > pre>
我非常感谢您对此问题进行排序解决方案
private 静态 无效 XMLPHOTO(字符串 xmlFilePath,字符串 imgURLVal,字符串 linkURLVal,字符串 titleVal,字符串 descVal)
{
XmlDocument XD = 新 XmlDocument();
XD.Load(xmlFilePath);
XmlNode Root = XD.SelectSingleNode(" );
XmlNode照片= Root.AppendChild(XD.CreateElement(" )));
XmlAttribute PhotAtr1 = Photo.Attributes.Append(XD.CreateAttribute(" )));
PhotAtr1.InnerText = imgURLVal;
XmlAttribute PhotAtr2 = Photo.Attributes.Append(XD.CreateAttribute(" )));
PhotAtr2.InnerText = linkURLVal;
// Child.InnerText =节点内部文本";
XmlNode title = Photo.AppendChild(XD.CreateElement(" )));
title.InnerText = titleVal;
XmlNode desc = Photo.AppendChild(XD.CreateElement(" )));
desc.InnerText = descVal;
XD.Save(xmlFilePath);
}
使用此代码...
它确实可以满足您的需求.确保您不会在XD.Load
处收到错误消息Hi,
I am working in a asp.net application which deals with inserting images into a folder and the path to xml file.So that they are visible in a gallery.I have the xml file. I need to enter the data dynamically to xml file
<pre lang="xml"><photos>
<photo imageurl="imgs/img 1.jpg" linkurl="http://www.google.com">
<title>hi1</title>
<description>Demo</description>
</photo>
</photos>
I would be extremely thankful for sorting this issue
解决方案 private static void XMLPHOTO(string xmlFilePath,string imgURLVal, string linkURLVal, string titleVal, string descVal )
{
XmlDocument XD = new XmlDocument();
XD.Load(xmlFilePath);
XmlNode Root = XD.SelectSingleNode("//Photos");
XmlNode Photo = Root.AppendChild(XD.CreateElement("Photo"));
XmlAttribute PhotAtr1 = Photo.Attributes.Append(XD.CreateAttribute("imageurl"));
PhotAtr1.InnerText = imgURLVal;
XmlAttribute PhotAtr2 = Photo.Attributes.Append(XD.CreateAttribute("linkurl"));
PhotAtr2.InnerText = linkURLVal;
//Child.InnerText = "Node Innertext";
XmlNode title = Photo.AppendChild(XD.CreateElement("Title"));
title.InnerText = titleVal;
XmlNode desc = Photo.AppendChild(XD.CreateElement("Description"));
desc.InnerText = descVal;
XD.Save(xmlFilePath);
}
Use this code...
it does what exactly you want. Make sure you dont get error at XD.Load
这篇关于将图像插入xml文件中的文件夹和路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文