IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

Disabling short format in code generation Options · View
coco
Posted: Wednesday, July 1, 2009 7:11:02 PM
Rank: Newbie

Joined: 7/1/2009
Posts: 2
Location: Brazil
Hi,

I am facing a small problem with the C++ code generated by Altova. I use this C++ code to generate XML files based on XSD files.

When I define in a .xsd that an element have the property minOcc = 0, it allows me to create an .xml with 0 instances of that element. In this case, Altova C++ code uses the short format for empty elements.

For instance, instead of generating the following code:

<?xml version="1.0" encoding="UTF-8"?>
<INST_SIM></INST_SIM>

...it generates the following one:

<?xml version="1.0" encoding="UTF-8"?>
<INST_SIM/>

I can change disable this short format in XMLSpy IDE, so I can generate xml samples in the first way. But I do not know how to disable it in the code generation. My code always generate in the second way.

Does anyone know how to change it? Do I need to change the templates SPL? (I have no experience is doing that).

Thanks in advance.
(using Altova XMLSpy Enterprise Edition v 2007, generating C++ for .NTE 2003, MSXML4 library)
rip
Posted: Thursday, July 2, 2009 12:07:27 PM
Rank: Advanced Member

Joined: 7/17/2008
Posts: 185
Location: Minutiae, Triviality
coco wrote:

When I define in a .xsd that an element have the property minOcc = 0, it allows me to create an .xml with 0 instances of that element. In this case, Altova C++ code uses the short format for empty elements.


Hi, this might be just a question of language, but the above paragraph is incorrect.

with a property of minOccurs=0, here is an example of occurances equal to zero:

<?xml version="1.0" encoding="utf-8"?>


Here is an example of 1 occurance of foo, foo is empty:

<?xml version="1.0" encoding="utf-8"?>
<foo/>

An element might not occur, occur but be empty, or have content.

Also, for XML,

<foo/>

and

<foo></foo>

are in every way syntactically equivalent. do you have a tool which is treating them differently? If so, then it is not spec.

There's a difference between an element in the DOM and its serialization as XML. When the binding serializes an existing element (it exists in the DOM), one that has no content, it serializes it as "<foo/>". So look in the serialization code.

if you can find the library that serializes the DOM (I have no experience with the c++ binding librairies), and make changes that cause an empty element to be serialized as "<foo></foo>", you should then be able to make the same changes in the spl. mostly, the spl for the serialization will probably be 'generic' code, and will be entire files copied into the binding, so it will be easy to find and alter. it's only when the changes are needed in code that is directly related to the schema's design that the SPL gets tricky.


coco
Posted: Saturday, July 4, 2009 6:03:09 PM
Rank: Newbie

Joined: 7/1/2009
Posts: 2
Location: Brazil
You are right, rip: the short format is a standard representation for empty elements (nothing related to occurences).

About the tools, unfortunately, I am using a .txt reader (legacy tool) as a .xml reader. This tool is not prepared for the short format, so I have to enforce the generation of the open tags and close tags.

Thanks for your help.

Users browsing this topic
guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.