Hello,
I am new to Castor, and am trying to figure out a way to use single quote for attributes when an object is marshalled using castor Marshaller class.
Here is what I did
1. create a schema based on user request.
2. generate classes including descriptor classes from the schema using SourceGenerator.
3. user Marshaller.marshall() method in my program.
Everything worked except that my user asked to use single quote for element attribue(s) while the marshalled xml string I got use double quote for attribute(s).
Here is my sample output, and I want to replace all the double quote with single quote for attribute values.
*************************************************************************************************************************
<?xml version="1.0" encoding="UTF-8"?>
<PSXMLOut>
<EducationGoals>
<EducationGoal StudentName="student "test""
YearsUntilNeed="0" YearsOfNeed="5" AnnualAmount="29993.0"
InflationRate="0.07" PortionToFund="1.0" SchoolName="student 'test > < <>"/>
</EducationGoals>
<AccumulationGoals>
<AccumulationGoal Description="hgfh" YearsUntilNeed="-1"
YearsOfNeed="33" AnnualAmount="3333.0" InflationRate="0.03" PortionToFund="1.0"/>
</AccumulationGoals>
<SpendingGoals>
<SpendingGoal RetirementSpendingGoal="0.0"/>
</SpendingGoals>
</PSXMLOut>
*******************************************************************************
In addition, I also noticed that double quotes in the actual value of an attribute is escaped while single quote is not. For example, the value for StudentName attribute of element EducationGoal is
student "test";
As shown in the above test, double quotes are escaped correctly. Since I am supposed to use single quotes for attribute value, I hope once I make the switch successfully, the single quote(s) in the attribute value will be escaped correctly.
My third question is that ">" symbol are not escaped, but the "<" are in the value of attribute SchoolName of element EducationGoal. Here is the value of the SchoolName:
Student 'test ><>
Is it correct?
My fourth question: I am not supposed to write the encoding information in <?xml version="1.0" encoding="UTF-8"?>. How do I do it?
Also, in my XML schema, I tried using single quotes for attribute, but it doesn't seem to have any effect on the marshalling results.
Here is a section of the schema:
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<element name="PSXMLIn">
<complexType>
<sequence>
<element name="Method">
<complexType>
<sequence>
<element name="Parameter" maxOccurs="4">
<complexType>
<sequence></sequence>
<attribute name="name" type="string"></attribute>
<attribute name="value" type="string"></attribute>
</complexType>
</element>
</sequence>
<attribute name="Action" type="string"></attribute>
</complexType>
</element>
</sequence>
</complexType>
</element>
</schema>
Your help is greatly appreciated.
Thanks in advance.
June

