XmlSpy 2013 を使用して、スキーマから Java でプログラム コードを生成しました。私のアプリケーションは基本的に、ファイルから 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 でドキュメントの名前空間を修飾する方法を知っている人はいますか? 助けてくれてありがとう。