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.

xml comments Options · View
caleb_r_miller
Posted: Wednesday, April 1, 2009 5:23:36 PM
Rank: Newbie

Joined: 12/19/2008
Posts: 2
Is there a way, using the 2007 R3 XML Spy generated code (both Java and C++) to insert an XML comment.

It looks like it might have been there in earlier versions of the generated code, but with the current move away from CDoc it no longer appears to be operational.

Thanks,
Caleb
island
Posted: Tuesday, April 7, 2009 9:15:31 AM
Rank: Newbie

Joined: 10/28/2002
Posts: 1,283
Location: AT
In order to create a comment in the code you will have to access the DOM, create the comment node with the DOM and then insert /
append the comment in the correct place (also using the DOM). For example assuming that you generate java code from the
following schema named example.xsd:


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="a">
<xs:complexType>
<xs:sequence>
<xs:element name="b">
<xs:complexType>
<xs:sequence>
<xs:element name="c" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>


If we create a new xml document and want to append a comment after the child element "c". We would do the following:

com.example.example2 doc = com.example.example2.createDocument();
com.example.aType root = doc.a.append();
com.example.bType b = root.b.append();
b.c.append().setValue("this is the element c");

/* use getNode to get the DOM node and appendChild to append this to the DOM structure. the parameter passed to this method
must be a new comment node which is created by accessing the OwnerDocument method */

b.getNode().appendChild(b.getNode().getOwnerDocument().createComment("this is a comment"));


doc.saveToFile("c://23146//example1.xml", true);


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.