DOM4JÉú³ÉXMLÎĵµ
public int createXMLFile(String filename) {
int returnValue = 0;
Document document = DocumentHelper.createDocument(); //Éú³ÉDocument£¬ÓÃÓÚ¹ÜÀíXMLÎĵµ
Element booksElement = document.addElement("books"); //Ìí¼Ó¸ù½Úµã
booksElement.addComment("This is a test for dom4j, holen, 2004.9.11"); //Ìí¼Ó×¢ÊÍ
Element bookElement = booksElement.addElement("book"); //ÔÚ¸ú½ÚµãbooksÏÂÌí¼ÓÒ»¸öbook×Ó½Úµã
bookElement.addAttribute("show", "yes"); //ΪbookElementÌí¼ÓÊôÐÔ£¬²¢Öƶ¨ÊôÐÔµÄÖµ
Element titleElement = bookElement.addElement("title"); //ΪbookElement½ÚµãÌí¼ÓÒ»¸ötitle×Ó½Úµã
titleElement.setText("Dom4j Tutorials"); //Ϊtitle×Ó½ÚµãÉèÖÃÎı¾½ÚµãÄÚÈÝ
try {
XMLWriter writer = new XMLWriter(new FileWriter(new File(filename)));
writer.write(document); //ÆÕͨ¸ñʽ£¬±È½Ï²»ÃÀ¹Û
OutputFormat format =null;
// format=OutputFormat.createPrettyPrint(); //ÃÀ»¯¸ñʽ,¶ÁÈ¡ºóÃÀ»¯ÏÔʾ
// writer = new XMLWriter( System.out, format );
// writer.write( document );
// format = OutputFormat.createCompactFormat(); //Ëõ¼õ¸ñʽ£¬¶ÁÈ¡ºóËõ¼õÏÔʾ
// writer = new XMLWriter( System.out, format );
// writer.write( document );
writer.close();
return
Ïà¹ØÎĵµ£º
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Xml;
using System.IO;
using System.Data;
using System.Dat ......
1¡¢µ¼³öµ½XMl select * from Brand for xml auto ,root('Brands')
<Brands>
<Brand BrandID="E584596D-4D66-4F2F-B6F7-71C3BEB4CA21" Name="inganico" />
<Brand BrandID="19B04451-DDC4-4CDF-BE30-CB4E703B27DA" Name="°²¸¶´ï" />
<Brand BrandID="3C6C8E12-7C4A-4F1 ......
Java codeFormat ft=Format.getRawFormat();
ft.setEncoding("utf-8");
ft.setIndent(" ");//ÉèÖÃËõ½ø
XMLOutputter outputter=new XMLOutputter(ft);//ÉèÖÃXML¸ñʽ
Õâλ˵µÄ²»´í£»
ÔÚieÀïÃæ£¬ËüÄܰÑxml×Ô¶¯½âÎö³ÆÊ÷Ðνṹ£¬ËùÒÔ¿´ÆðÀ´Ã»ÎÊÌ⣬ÔÚ¼Çʱ¾ÀïÃæ£¬¾Í²»ÐÐÁ ......
Definition comparer class,
class ItemComparer : IEqualityComparer<XElement>
{
public bool Equals(XElement x, XElement y)
{
return x.Attribute("Name").Value == x.Attribute("Name").Value;
}
public int GetHashCode(XElement obj)
......