小毛驴xml初步试验
XmlDocument xmldoc = new XmlDocument();//创建xml文档对象
XmlNode root;//根节点
xmldoc.Load(Server.MapPath("address.xml"));//加载xml文档
root = xmldoc.DocumentElement;//获取根节点
XmlElement student = xmldoc.CreateElement("student");//创建元素
XmlElement node1 = xmldoc.CreateElement("stuName");
node1.InnerText = stuName.Text.Trim();//给元素内文本赋值
XmlElement node2 = xmldoc.CreateElement("phone");
node2.InnerText = phone.Text.Trim();
XmlElement node3 = xmldoc.CreateElement("qq");
node3.InnerText = qq.Text.Trim();
XmlElement node4 = xmldoc.CreateElement("email");
node4.InnerText = email.Text.Trim();
XmlElement node5 = xmldoc.CreateElement("home");
node5.InnerText = home.Text.Trim();
XmlElement node6 = xmldoc.CreateElement("headImage");
node6.InnerText = headImage.Text.Trim();
XmlElement node7 = xmldoc.CreateElement("work");
node7.InnerText = work.Text.Trim();
student.AppendChild(node1);//将指定节点添加到该节点子节点列表的末尾
student.AppendChild(node2);
student.AppendChild(node3);
student.AppendChild(node4);
相关文档:
Struts 2 使用XML文件校验例题
在这个例子中我们将了解到怎么样通过XML文件来进行校验。XML校验文件必须以"动作(action)类-Validation.xml"的形式命名。在这个例子中,动作(action)类名是"Login.java",XML文件名是"Login-Validation.xml"。
Login-validation.xml的文件内容如下:
<!DOCTYPE validators PUBLIC "-//O ......
使用XMLList读取XML数据
XML对象提供了一个返回XMLList类型的方法elements(),既返回所有XML对象的子元素节点,随后我们可以通过for each语句循环则可访问到整个XML数据内容。以上面创建内部XML文档的XML数据为例,详细见如下代码块:
varlist:XMLList=pXml.elements();
foreach(varelement:XMLinlist)
{
// ......
import java.awt.Image;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
public class createXml
{
public static boolean writeXml(String path,String dir,String wpath,String wname)
{
File[] files = ReaderListFiles(path);
boo ......
<?xml version="1.0" encoding="utf-8"?>
<LinkLibrary xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Link Cat="aa" Url="aa" Desc="aa" />
<Link Cat="bb" Url="aa" Desc="aa" />
<Link Cat="cc" Url="aa" Desc="aa" />
&l ......
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using i_salesDAL;
using i_s ......