package com.smtscript.lib; import org.dom4j.Attribute; import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.io.SAXReader; import com.smtscript.lib.xml.JSXmlDocument; import com.smtscript.lib.xml.JSXmlModify; public class JSStaticXml extends JSStaticAbstract { public JSXmlDocument open(String fileName) throws Exception { SAXReader reader=new SAXReader(); Document doc=reader.read(_parentScope.__findExistFile__(fileName, true).open()); return new JSXmlDocument(_parentScope, doc); } public JSXmlDocument load(String xmlString) throws Exception { SAXReader reader=new SAXReader(); Document doc=reader.read(xmlString); return new JSXmlDocument(_parentScope, doc); } public String getAttrValue(Element elem, String attrName, String defVal) { Attribute attr = elem.attribute(attrName); if(attr == null) return defVal; return attr.getText(); } public String getAttrValue(Element elem, String attrName) throws Exception { String value = getAttrValue(elem, attrName, null); if(value == null) throw new Exception("can't find attr name : " + attrName); return value; } public JSXmlModify openModify(String xmlFile) throws Exception { return new JSXmlModify(xmlFile, true, this); } public JSXmlModify loadModifyString(String xmlString) throws Exception { return new JSXmlModify(xmlString, false, this); } }