以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 DOM/SAX/XPath 』  (http://bbs.xml.org.cn/list.asp?boardid=11)
----  请教dom4j中,如何将xsd文件以字符串的形式载入?  (http://bbs.xml.org.cn/dispbbs.asp?boardid=11&rootid=&id=46177)


--  作者:fzxugang
--  发布时间:4/28/2007 9:08:00 AM

--  请教dom4j中,如何将xsd文件以字符串的形式载入?
想写一个用xsd校验xml的程序,代码如下:
 public static void main(String args[]) throws SAXException, DocumentException, IOException
 {
  SAXReader reader = new SAXReader();
  reader.setValidation(true);
  reader.setFeature("http://xml.org/sax/features/validation", true);
  reader.setFeature("http://apache.org/xml/features/validation/schema", true);
  
//  InputStream in = new ByteArrayInputStream(xsdString().getBytes());
  reader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
  "D://TestJunit/doc/rdzjgsf.xsd");
//    parseXMLDocument(xsdString()));

  
  XMLErrorHandler errorHandler = new XMLErrorHandler();
  reader.setErrorHandler(errorHandler);
  
  File file = new File("D://TestJunit/doc/rdzjgsf1.xml");
//  InputStream file = new ByteArrayInputStream(xmlString().getBytes());
  Document document = reader.read(file);
  XMLWriter writer = new XMLWriter(OutputFormat.createPrettyPrint());
  if (errorHandler.getErrors().hasContent()) {
          writer.write(errorHandler.getErrors());
  } else {
          System.out.println("validate success.");
  }
 }


如果xsd和xml都是文件形式的话,以上代码可以实现了,现在想xsd和xml都从字符串中读取,xml的也已经解决了,xsd的不知道要怎么实现:
reader.setProperty的第二个参数是一个object对象,指向文件的路径,那现在字符串要如何转换成能接受的参数呢?
或有其他的解决方法?


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms