Frage

I have used XmlSpy 2013 to generate program code in Java from a schema. My application basically reads in xml from a file, modifies the xml, and writes it back out to the file. The generated code provides classes and functions to do the load:

sampleSchema2 doc = sampleSchema2.loadFromFile(filePath);
// Load the file into Java objects...

and to write the file back out:

sampleSchema2 sampleDoc = sampleSchema2.createDocument();
// Populate the doc from the modified Java objects...
sampleDoc.saveToFile(path, true);

The schema I used to generate the code has the following attributes:

<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">

The xml files I read in use qualified namespaces for the elements like so:

<?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>

...

But after I write the file out again using saveToFile() as above, all of the qualified namespaces are removed from the elements like so:

<?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>

...

Does anyone know how I can get xmlspy to qualify the namespaces on the documents so they look like how I read them in? Thank you for any help.

War es hilfreich?

Lösung

As it turns out, this is currently impossible using Altova generated code per my response from Altova technical support:

Thanks for contacting us.

I'm afraid that it's currently not presently possible to control the namespace prefix in the generated code.

I'll forward your message on to our development team for future consideration.

Best regards,

Mxxxxxxxx Kxxxxx
Support Engineer
Altova GmbH

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top