View Issue Details

IDProjectCategoryView StatusLast Update
0002368JEDI VCL00 JVCL Componentspublic2004-12-11 03:10
ReporteranonymousAssigned To 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.00 BETA 2 
Target VersionFixed in Version3.00 RC 1 
Summary0002368: TJvSimpleXML - reading properties with "default value" when using "sxoAutoCreate"
DescriptionWhen
a) reading property element: TJvSimpleXMLProps.value(X,Y)
b) property X does not exists
c) supplies a default value Y (not an empty string)
d) sxoAutoCreate is a member of TjvSimpleXML.options.

The result of TJvSimpleXMLProps.value(X,Y) will not be the value Y, but rather an empty string.
Additional InformationThis code illustrates the problem;

procedure TForm1.Button1Click(Sender: TObject);
var xml :TjvSimpleXML;
    a :string;
begin
  xml:=TjvSimpleXML.create(application);
  xml.Options:=[sxoAutoCreate];
  a:=xml.Root.Properties.Value('TEST','DEFAULT');
  if a='DEFAULT' then
    showmessage('I''m default')
  else if a='' then
    showmessage('Oops, autocreated empty property');
end;

Running the example, 'a' will contain an empty string, not the value 'DEFAULT' as I would expect.
The problem lies in method TJvSimpleXMLProps.GetItemNamed which automaticly create the property with empty string. It looks like it would be safe to return nil instead of creating within TJvSimpleXMLProps.GetItemNamed.

TagsNo tags attached.

Activities

user72

2004-12-09 12:22

  ~0005847

Try the attached update.

anonymous

2004-12-09 15:08

viewer   ~0005849

Thanks Peter, attached file solved the problem.

mliesen

2004-12-09 19:05

reporter   ~0005850

Last edited: 2004-12-09 19:06

I just noticed that the TJvSimpleXMLElems.Value(x,y) has the same problem (using the JvSimpleXml041209.zip)

New example code:

procedure TForm1.Button1Click(Sender: TObject);
var xml :TjvSimpleXML;
  a :string;
begin
  xml:=TjvSimpleXML.create(application);
  xml.Options:=[sxoAutoCreate];
  a:=xml.Root.Items.Value('TEST','DEFAULT');
  if a='DEFAULT' then
    showmessage('I''m default')
  else if a='' then
    showmessage('Oops, autocreated empty value');
end;

2004-12-10 05:15

 

JvSimpleXml041210.zip (14,867 bytes)

user72

2004-12-10 05:15

  ~0005851

Try the new file attached

mliesen

2004-12-10 16:50

reporter   ~0005859

Almost there, line 121 and 1854;

function GetItemNamedDefault(const Name): TJvSimpleXMLProp;
should be
function GetItemNamedDefault(const Name, Default: string): TJvSimpleXMLProp;

With the above change, it works like charm. Thanks!

user72

2004-12-11 03:10

  ~0005860

Updated in CVS

Issue History

Date Modified Username Field Change
2004-12-08 17:14 anonymous New Issue
2004-12-09 12:22 user72 File Added: JvSimpleXml041209.zip
2004-12-09 12:22 user72 Note Added: 0005847
2004-12-09 12:22 user72 Status new => feedback
2004-12-09 15:08 anonymous Note Added: 0005849
2004-12-09 19:05 mliesen Note Added: 0005850
2004-12-09 19:06 mliesen Note Edited: 0005850
2004-12-10 05:14 user72 File Deleted: JvSimpleXml041209.zip
2004-12-10 05:15 user72 File Added: JvSimpleXml041210.zip
2004-12-10 05:15 user72 Note Added: 0005851
2004-12-10 16:50 mliesen Note Added: 0005859
2004-12-11 03:10 user72 Status feedback => resolved
2004-12-11 03:10 user72 Resolution open => fixed
2004-12-11 03:10 user72 Assigned To => user72
2004-12-11 03:10 user72 Note Added: 0005860
2004-12-11 03:10 user72 Assigned To user72 =>