以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 DTD/XML Schema 』  (http://bbs.xml.org.cn/list.asp?boardid=23)
----  [救助] 用xsd文件规则解析xml问题  (http://bbs.xml.org.cn/dispbbs.asp?boardid=23&rootid=&id=63418)


--  作者:Holyan
--  发布时间:6/3/2008 6:00:00 PM

--  [救助] 用xsd文件规则解析xml问题
[color=#9900FF]   JAXBContext jc = JAXBContext
     .newInstance("jp.co.fujifilm.opj.obsys.ips.order");
   Unmarshaller u = jc.createUnmarshaller();

   order = (Order) u.unmarshal(orderXml);
   File xsdFile = new File("schema/order.xsd");
   
   SchemaFactory schemaFactory = SchemaFactory
     .newInstance("http://www.w3.org/2001/XMLSchema");
   Schema schema = schemaFactory.newSchema(xsdFile);
   u.setSchema(schema);

代码片段


xsd片段
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns="http://ips.poi.de/schemas/orderexport"
 targetNamespace="http://ips.poi.de/schemas/orderexport"
 elementFormDefault="qualified">
 <!--
  - Common types
 -->
 <xs:complexType name="empty" />
 <xs:simpleType name="id">
  <xs:restriction base="xs:integer">
   <xs:minInclusive value="1" />
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="name">
  <xs:restriction base="xs:token">
   <xs:minLength value="2" />
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="email">
  <xs:restriction base="xs:token">
   <xs:pattern value=".+@.+\..+" />
  </xs:restriction>
 </xs:simpleType>


将其解析并与数据库相连  然后往xml文件写入新数据
求解高手建议
[/color]


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