ͨ¹ýDOM4J½âÎöXMLÎļþС½á
´´½¨XMLÎļþ£º
public boolean createXML(){
try{
Document doc = DocumentHelper.createDocument();
Element root = doc.addElement("root");
Element personNode = root.addElement("person");
Element sonNode = personNode.addElement("fristson");
sonNode.setText("lk1");
Element sonNode2 = personNode.addElement("secandtson");
sonNode2.setText("lk2");
OutputFormat opf = OutputFormat.createPrettyPrint();
opf.setEncoding("GB2312");
XMLWriter xmlw = new XMLWriter(new FileWriter("d:\\myXML.xml"),opf);
xmlw.write(doc);
xmlw.close();
return true;
}catch(Exception e){
System.out.println("error: In create XML");
return false;
}
}
ÒÔÉÏÖ»ÊǸö¼òµ¥µÄ´´½¨ÁËÒ»¸öXMLÎļþÔÚDÅÌÏ£¬Ï±ßÖ÷ÒªÊÇ·ÖÎöXMLÎļþ£¬ÌáÈ¡Ãû×ÖºÍÄÚÈÝ£ºÒÔJAVAÏîÄ¿ÖУ¬¾µäµÄWEB.XMLΪÀý
public boolean updateXML(){
Document doc = null;
try{
SAXReader sr = new SAXReader();
doc = sr.read(new File("d:\\web.xml"));
Element personRoot = doc.getRootElement();
Iterator personNode = personRoot.elementIterator();
while(personNode.hasNext()){
Element sonNode = (Element)personNode.next();
List sonNodes = sonNode.elements();
System.out.println(sonNode.getName());
for(int i = 0 ;i<sonNodes.size() ; i++){
System.out.println(i+":"+((Element)sonNodes.get(i)).getName());
System.out.println(i+":"+((Element)sonNodes.get(i)).getText());
}
Ïà¹ØÎĵµ£º
¼òµ¥µØ˵£¬xslÊÇ˵Ã÷xmlÈçºÎ±í´ï³öÀ´µÄÑùʽÎļþ£¬¶øxsd¸ø³öxmlÎļþµÄ¸ñʽÃèÊö
Èç¹û˵xmlÊÇÒ»µþ³®Æ±£¬xsd¾ÍÊÇÑé³®»ú£¬¿´¿´ÀïÃæÓÐûÓмٳ®£¬¶øxslÊǵ㳮»ú£¬¿´¿´µ½µ×ÊǶàÉÙÇ®¡£ÓÃxml¿ÉÒÔ²»ÓÃxsd£¬¾ÍÏñ»¨Ç®µÄʱºò²»Ò»¶¨ÒªÑé³®Ò»Ñù£¬µ«ÊÇÊÕÇ®µÄÈËÒ»°ãÊÇÏëÒªÑéµÄ¡£¶ø»¨Ç®µÄʱºò²»Äܲ»µã³®£¬²»µãÄǾͲ»ÊÇ»¨Ç®ÁË£¬ÊÇÍæÇ®¡£µ±È»ÁË£ ......
XPath Óï·¨
2007-06-05 17:24
XPath Óï·¨
×÷Õß:w3pop.com ·Òë/ÕûÀí:w3pop.com ·¢²¼:2007-04-29 ä¯ÀÀ:674 :: ::
XPath Nodes(½Úµã) XPath Axes
XPath uses path expressions to select nodes or node-sets in an XML document. The node is selected by following a path or steps.
XPath ͨ¹ý·¾¶±í´ïʽ´ÓXM ......
ÎÊÌâÃèÊö£º
jbossÓ¦Ó÷þÎñÆ÷£¬Ê¹ÓÃspring
ÎÞ·¨Æô¶¯·þÎñ£¬´íÎóÈÕÖ¾£º
[org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@155d3a3] does not
support XML Schema. Are you running on Java 1.4 or below with Apache
Crimson? Upgrade to Apache Xerces (or Java 1.5) for full XSD ......
public static IList<News> GetAllNews()
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load("Äã¶ÁÈ¡µÄµØÖ·£ºÀýÈç ......
À©Õ¹±ê¼ÇÓïÑÔXML£¨eXtensible Markup Language£©£¬ÊÇÓÉW3C×éÖ¯Öƶ¨µÄ¡£×öΪÓÃÓÚÌæ´úHTMLÓïÑÔµÄÒ»ÖÖÐÂÐ͵ıê¼ÇÓïÑÔ£¬XMLÄÚ²¿ÓÐןܶà»ù±¾±ê×¼£¬XML¾ÍÊÇͨ¹ýÓëÕâЩÏà¹Ø±ê×¼µØ½áºÏ£¬Ó¦ÓÃÓÚ¿Æѧ¼ÆËã¡¢µç×Ó³ö°æ¡¢¶àýÌåÖÆ×÷ºÍµç×ÓÉÌÎñµÄ¡£C££×÷ΪһÖÖÐÂÐ͵ijÌÐòÓïÑÔ£¬ÊÇ.Net¿ò¼ÜµÄÒ»¸öÖØÒª×é³É²¿·Ö£¬ËûºÍXMLµÄ¹ØϵÆÄÉî¡£±¾ÎÄ¾Í´Ó ......