我已经使用Java2013从模式中生成了XmlSpy程序代码。我的应用程序基本上是从文件中读入xml,修改xml,然后将其写回文件。生成的代码提供了执行加载的类和函数:
sampleSchema2 doc = sampleSchema2.loadFromFile(filePath);
// Load the file into Java objects...并将文件写回:
sampleSchema2 sampleDoc = sampleSchema2.createDocument();
// Populate the doc from the modified Java objects...
sampleDoc.saveToFile(path, true);我用来生成代码的模式具有以下属性:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:bfrs="http://www.example.com/schema/bfrs" xmlns:cnc="http://www.example.com/schema/cnc" targetNamespace="http://www.example.com/schema/cnc" elementFormDefault="qualified" attributeFormDefault="unqualified" version="2006/05/30" xml:lang="en">我在中读到的xml文件对元素使用了限定的名称空间,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<cnc:cnc versionNumber="v.2.2.1" versionDate="2012-04-03" xsi:schemaLocation="http://www.example.com/schema/cnc exampleSchema.xsd" xmlns:cnc="http://www.example.com/schema/cnc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<cnc:Revisions>
<cnc:Revision>S003</cnc:Revision>
</cnc:Revisions>..。
但是在我像上面一样使用saveToFile()再次写出文件之后,所有符合条件的名称空间都被从元素中删除了,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<cnc versionNumber="v.2.2.1" versionDate="2012-04-03" xmlns:cnc="http://www.example.com/schema/cnc">
<Revisions>
<Revision>S003</Revision>
</Revisions>..。
有人知道怎样才能让xmlspy限定文档上的名称空间,使它们看起来像我读取它们的样子吗?谢谢你的帮助。
发布于 2013-07-25 04:31:26
事实证明,这是目前不可能使用Altova生成的代码根据我对Altova技术支持的回应:
感谢您与我们联系。
恐怕目前还不能在生成的代码中控制名称空间前缀。
我会将您的消息转发给我们的开发团队,以供将来考虑。
诚挚的问候,
Mxxxxxxxx Kxxxxx
支持工程师
Altova GmbH
https://stackoverflow.com/questions/17453504
复制相似问题