100分: xml中可以再套入一个 xml吗? 节点就是另外一个xml文件的名称不就可以了吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /* * Created by IntelliJ IDEA. * User: ylf * Date: Aug 29, 2002 * Time: 9:05:53 AM * To change template for new class use * Code Style | Class Templates options (Tools | IDE Options). */package parser_xml;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.Text;import org.apache.crimson.tree.XmlDocument;import org.jdom.DocType;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.DocumentBuilder;import java.io.FileOutputStream;public class NewXml { public NewXml() throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.newDocument(); DocType doctype = new DocType("lable","label.DTD"); Element root = doc.createElement("yanglongfei"); Text text = doc.createTextNode("yanglongfei"); root.appendChild(text); ImportXml ixl = new ImportXml(); Element dd = ixl.k(); Element dt = (Element) doc.importNode(dd, true); root.appendChild(dt); doc.appendChild(root); ((XmlDocument) doc).write(new FileOutputStream("c:\\kkk.xml")); } public static void main(String args[]) throws Exception { NewXml newXml = new NewXml(); }}class ImportXml { public ImportXml() { } public Element k() throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse("books.xml"); Element dd = doc.getDocumentElement(); return dd; }}你要的是这种效果吧 disk(谁说东北人都是活雷锋!瞎掰!!) :那我在DTD中如何定义将导入XML这样的一个节点,我想专门用一个ELEMENT来处理该XML..... 只要将所需的XML流作为一个子节点放到另一个XML流的某个节点下即可。Element graphElement = XMLDocUtils.getChild(element,"resrelationpath",false);String XMLTEMP = XMLDocUtils.toXML(graphElement,null,null);这样就可以啦 DTD Example:<!ENTITY writer SYSTEM "http://www.w3schools.com/entities/entities.xml"> 如果这两个节点来自不同的文档,你必须用document的importNode方法 求助:Socket传输Object类型时,出现ClassNotFound异常 Tomcat控制台org.apache.catalina.core.StandardContext reload Java单元测试 JUnit 4.8.1 发布 hibernate_查询 sogo浏览器 下载报表 下载.action 请问有什么好用的编写jsp的工具么? struts:表单中提交的内容有特殊字符怎么解决(急!) 不知128M内存能不能运行weblogic server? 各位,请推荐几本学习Java的必要、经典之作! sos! 帮帮忙! 新版SJEP平台,轻松开发部署EJB应用 xml得不到文档
* Created by IntelliJ IDEA.
* User: ylf
* Date: Aug 29, 2002
* Time: 9:05:53 AM
* To change template for new class use
* Code Style | Class Templates options (Tools | IDE Options).
*/
package parser_xml;import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
import org.apache.crimson.tree.XmlDocument;
import org.jdom.DocType;import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import java.io.FileOutputStream;public class NewXml {
public NewXml() throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
DocType doctype = new DocType("lable","label.DTD");
Element root = doc.createElement("yanglongfei"); Text text = doc.createTextNode("yanglongfei");
root.appendChild(text);
ImportXml ixl = new ImportXml();
Element dd = ixl.k();
Element dt = (Element) doc.importNode(dd, true);
root.appendChild(dt);
doc.appendChild(root);
((XmlDocument) doc).write(new FileOutputStream("c:\\kkk.xml"));
} public static void main(String args[]) throws Exception {
NewXml newXml = new NewXml();
}
}class ImportXml {
public ImportXml() {
} public Element k() throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse("books.xml");
Element dd = doc.getDocumentElement();
return dd;
}
}
你要的是这种效果吧
那我在DTD中如何定义将导入XML这样的一个节点,我想专门用一个ELEMENT来处理该XML.....
Element graphElement = XMLDocUtils.getChild(element,"resrelationpath",false);
String XMLTEMP = XMLDocUtils.toXML(graphElement,null,null);
这样就可以啦
SYSTEM "http://www.w3schools.com/entities/entities.xml">