Topic: 用Castor输出XML的格式问题!熟悉Castor的高手请进! |
Print this page |
1.用Castor输出XML的格式问题!熟悉Castor的高手请进! | Copy to clipboard |
Posted by: Javrmi Posted on: 2003-07-06 16:09 我用Castor输出的XML全都挤在一起,没有换行没有缩进,请问如何让Castor输出时提供缩进和换行! 另外发现Castor的encoding也有问题,当我的输出制定encoding为UTF-8时,若输出的XML中带有中文,用XMLSPY打开发现输出的全是乱码,同时报告该XML不是well-formed,更不用说通过validate!这个文件再用castor自身Unmarshaller,也报告非良构!因为castor使用marshaller时只能用Writer做为构造,而不使用Stream不知是否和这有关,请赐教! 我用的castor版本为0.9.5 操作系统XP JDK1.3.1_02 |
2.Re:用Castor输出XML的格式问题!熟悉Castor的高手请进! [Re: chm_main] | Copy to clipboard |
Posted by: yogurtpig Posted on: 2003-07-07 16:10 有中文的时候encoding要用gb2312.不然大多数parser都过不去. 好像到目前为止,我只见过perl的parser不用写对encoding就可以解析. 至于输出格式,如果是程序读那有没有换行和缩进都没有关系. 如果你真的要换行和缩进以后给自己看,那可以用spy另存一下或者自己写一个xslt就可以了. |
3.Re:用Castor输出XML的格式问题!熟悉Castor的高手请进! [Re: chm_main] | Copy to clipboard |
Posted by: Javrmi Posted on: 2003-07-07 19:46 我找到解决方法了,缩进是在castor的配置文件castor.properties中指定的! 在0.9.5版中默认是不缩进的!castor.properties配置如下(红色那行原本被注释掉了): # THE CASTOR PROPERTIES FILE # This file specifies values for Castor run-time # which may be configured by the user. # $Id: castor.properties,v 1.2 2003/03/25 20:32:25 snyder Exp $ # Defines the default XML parser to be used by castor # The parser must implement org.xml.sax.Parser # org.exolab.castor.parser=org.apache.xerces.parsers.SAXParser # Defines the default XML serializer to be used by castor # The serializer must implement org.apache.xml.serialize.Serializer # org.exolab.castor.serializer=org.apache.xml.serialize.XMLSerializer # Defines the NodeType for use with Java primitive types (int, long, # boolean, etc). This value is only used by the Introspector. # valid values are either "attribute" or "element". By default # all primitives are marshalled as attributes. Simply uncomment # the following line to change the NodeType to element. # #org.exolab.castor.xml.introspector.primitive.nodetype=element # Defines the Naming "style" or conventions to use when # creating XML names from Java class or field names. # Valid values are as follows: # ----------------------------------------------------------------- # lower (default) | All names are lowercase with hyphens # | separating words. # | # | Example: personInfo = person-info # ----------------------------------------------------------------- # mixed | All names are mixed case, with Uppercase # | character as the first letter of a new word. # | # | Example: personInfo = personInfo # | Example: FooBar = fooBar # ----------------------------------------------------------------- # {Any ClassName} | Any Class which implements # | org.exolab.castor.xml.XMLNaming # ----------------------------------------------------------------- # # By default all names are treated as the "lower" option. # To preserve the Java mixed-case conventions simply # uncomment the following line. # #org.exolab.castor.xml.naming=mixed ############################### # REGULAR EXPRESSION EVALUATORS # # Defines the Regular Expression Evaluator to be used by Castor # The evaluator must implement org.exolab.castor.util.RegExpEvaluator # # # An implementation which uses the Jakarta RegExp library org.exolab.castor.regexp=org.exolab.castor.util.JakartaRegExpEvaluator # An implementation which uses the Jakarta ORO library #org.exolab.castor.regexp=org.exolab.castor.util.JakartaOroEvaluator # # Uncomment the following to basically supress evaluation of Regular expressions #org.exolab.castor.regexp=org.exolab.castor.xml.util.AlwaysTrueRegExpEvaluator # True if all documents should be indented on output by default # org.exolab.castor.indent=true # True if xml documents should be validated by the SAX Parser # org.exolab.castor.parser.validation=true org.exolab.castor.parser.namespaces=false # True if all documents should be validated by the marshalling framework # org.exolab.castor.marshalling.validation=true # Comma separated list of SAX 2 features that should be enabled # for the default parser. # #org.exolab.castor.features= # True if should produce verbose messages # org.exolab.castor.debug=false # List of collection handlers for Java 1.1 and Java 1.2 run-times # org.exolab.castor.mapping.collections=\ org.exolab.castor.mapping.loader.J1CollectionHandlers,\ org.exolab.castor.mapping.loader.J2CollectionHandlers # List of persistence factories for the supported database servers # org.exolab.castor.jdo.engines=\ org.exolab.castor.jdo.drivers.OracleFactory,\ org.exolab.castor.jdo.drivers.PostgreSQLFactory,\ org.exolab.castor.jdo.drivers.SybaseFactory,\ org.exolab.castor.jdo.drivers.SQLServerFactory,\ org.exolab.castor.jdo.drivers.DB2Factory,\ org.exolab.castor.jdo.drivers.InformixFactory,\ org.exolab.castor.jdo.drivers.HsqlFactory,\ org.exolab.castor.jdo.drivers.InstantDBFactory,\ org.exolab.castor.jdo.drivers.InterbaseFactory,\ org.exolab.castor.jdo.drivers.MySQLFactory,\ org.exolab.castor.jdo.drivers.SapDbFactory,\ org.exolab.castor.jdo.drivers.GenericFactory # List of key generator factories # org.exolab.castor.jdo.keyGeneratorFactories=\ org.exolab.castor.jdo.drivers.MaxKeyGeneratorFactory,\ org.exolab.castor.jdo.drivers.HighLowKeyGeneratorFactory,\ org.exolab.castor.jdo.drivers.IdentityKeyGeneratorFactory,\ org.exolab.castor.jdo.drivers.SequenceKeyGeneratorFactory,\ org.exolab.castor.jdo.drivers.UUIDKeyGeneratorFactory # Collection handlers for the source code generator # org.exolab.castor.builder.type.j2=\ org.exolab.castor.builder.FieldInfoFactoryJ2 org.exolab.castor.builder.type.j1=\ org.exolab.castor.builder.FieldInfoFactory org.exolab.castor.builder.type.odmg=\ org.exolab.castor.builder.FieldInfoFactoryODMG30 # # TransactionManagerFactory implementations # org.exolab.castor.jdo.spi.transactionManagerFactories=\ org.exolab.castor.jdo.spi.WebSphereTransactionManagerFactory # # The buffer size in bytes for fetching LOBs (this is dependent upon # the JDBC driver implementation) - value below is 5k # org.exolab.castor.jdo.lobBufferSize=5120 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |