Re: [xml] xmlHashCreate and xmlHashAddEntry - hashs of unknown size?

2007-02-04 Thread Daniel Veillard
On Fri, Feb 02, 2007 at 09:54:51AM -0600, David Hagood wrote:
 Suppose I have a hash table who's size I do not know at compile time - it
 might end up with one entry or a thousand.
 
 What value should I pass to xmlHashCreate for the size?
 
 If I pass a value N, and at run time try to add N+1 items to the hash,
 will it error or will it just increase the hash size?

  Don't worry, go for the lower unless you know it will be huge.
The algorithm automatically adjusts the hash table size when it detects
the clash list is growing too long in an entry. The reajustment takes a
bit of computation though, which you can avoid if you know it will grow a
lot by giving a large initial value.

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard  | virtualization library  http://libvirt.org/
[EMAIL PROTECTED]  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/
___
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
http://mail.gnome.org/mailman/listinfo/xml


Re: [xml] Possible bug in libxml2?

2007-02-04 Thread Danilo Segan
Hi Daniel,

Јуче у 3:22, Daniel Leidert написа:

 I wanted to create a gettext portable object template (.pot) file from
 Norman Walsh's DocBook: The Definitive Guide. Therefor I used:
 
 xml2po -e -o book.pot book.xml
 
 in http://docbook.svn.sourceforge.net/viewvc/docbook/trunk/defguide/en/
 and received a segmentation fault. So I started gdb and got the attached
 backtrace. Can any of you say, where the segmentation fault is produced
 - in xml2po or libxml2/python-libxml2 - so I can file a bug-report?
 xmllint validates the XML source if you fix the tag element in
 refpages/elements/equation/refentry.xml (should be an sgmltag element).

It's most likely an xml2po bug.  Please file a bug (so it's not lost)
and I'll investigate:

  http://bugzilla.gnome.org/enter_bug.cgi?product=xml2po

Cheers,
Danilo
___
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
http://mail.gnome.org/mailman/listinfo/xml


Re: [xml] Necessary steps involved in validating against an

2007-02-04 Thread Eric.Zurcher
Hi,

Regaring Delphi programmer Erik Andersen's query about using an XSD when
using libxml2, I offer the code below, based on testSchemas.c, as a
simple example of how to accomplish this in a Delphi application
(although it wasn't entirely clear from his original question whether
Erik is developing his code in C or Delphi). 

Most of this is almost trivial. The biggest challenge is in developing
the error-handling code, as Delphi does not have an exact equivalent of
the C printf family of functions. 

The easiest way around this difficulty is to not bother calling either
xmlSchemaSetParserErrors or xmlSchemaSetValidErrors, and rely on the
default error handler. The default error handler in libxml2 will, I
believe, attempt to write any error message to stderr. This should work
OK in a console application, but is likely to fail if the application is
using a Windows GUI (since stderr is not well-defined in that
context). 

In the code below, I attempt to get around this problem in a very simple
way. ErrorFunc serves as the error-handling function. Using a bit of
declaration trickery to allow it to pass the parameters, it calls the
wvsprintf function provided by Windows to format the message string into
a buffer. The buffer is then written to a file, but the ctx parameter
could just as easily be used to pass a pointer to a Windows edit control
where the text could be displayed. 

I hope this helps.


/// 
program Schematest;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  windows,
  libxml2;

procedure ErrorFunc(ctx: pointer; const msg: PChar); cdecl;
var
  ptr_args: array[0..100] of Pointer absolute msg;
  buffer: string;
  len: integer;
type
  PFile = ^Text;
begin
  SetLength(buffer, 1024); // Allocate enough space
  len := wvsprintf(PChar(buffer), msg, @(ptr_args[1]));
  SetLength(buffer, len);  // Truncate to the actual string length
  if Assigned(ctx) then
write(PFile(ctx)^, buffer)
  else
write(buffer);
end;

var
  parserCtxt: xmlSchemaParserCtxtPtr;
  validCtxt: xmlSchemaValidCtxtPtr;
  doc: xmlDocPtr;
  schema: xmlSchemaPtr;
  ret: integer;
  logfile: Text;
begin
  if ParamCount  2 then
writeln('Usage: ' + ParamStr(0) + ' schemaFile xmlFile')
  else
  begin
AssignFile (logfile, 'test.log');
Rewrite(logfile);
parserCtxt := xmlSchemaNewParserCtxt(PChar(ParamStr(1)));
xmlSchemaSetParserErrors(parserCtxt,
xmlSchemaValidityErrorFunc(@ErrorFunc),
xmlSchemaValidityWarningFunc(@ErrorFunc),
@logfile);
schema := xmlSchemaParse(parserCtxt);
xmlSchemaFreeParserCtxt(parserCtxt);

if Assigned(schema) then
begin
  doc := xmlReadFile(PChar(ParamStr(2)), nil, 0);
  if (doc = nil) then
  writeln('Could not parse ' + ParamStr(2))
  else
  begin
validCtxt := xmlSchemaNewValidCtxt(schema);
xmlSchemaSetValidErrors(validCtxt,
xmlSchemaValidityErrorFunc(@ErrorFunc),
xmlSchemaValidityWarningFunc(@ErrorFunc),
@logfile);
ret := xmlSchemaValidateDoc(validCtxt, doc);
write (ParamStr(2));
if (ret = 0) then
  writeln (' validates')
else if (ret  0) then
  writeln (' fails to validate')
else
  writeln(' validation generated an internal error');
xmlSchemaFreeValidCtxt(validCtxt);
xmlFreeDoc(doc);
  end;
end;
CloseFile(logfile);
xmlSchemaCleanupTypes();
xmlCleanupParser();
  end;
end.


/// 

-Original Message-
Date: Fri, 2 Feb 2007 04:40:00 -0500
From: Daniel Veillard [EMAIL PROTECTED]
Subject: Re: [xml] Necessary steps involved in validating against an
XSD?
To: Erik F. Andersen [EMAIL PROTECTED]
Cc: xml@gnome.org
Message-ID: [EMAIL PROTECTED]
Content-Type: text/plain; charset=us-ascii

On Thu, Feb 01, 2007 at 11:50:23AM +0100, Erik F. Andersen wrote:
 Hello!
 
 I have looked at the code in xmllint.c because I need only the part
that validates a XML against a schema, that is:
 xmllint --schema xsdfile.xsd xmlfile.xml
 
 Since I'm a Delphi programmer and I'm not too experienced with C I
find the code in xmllint.c a bit confusing however (and I cannot debug
either).
 
 I was hoping that maby some kind soul would outline the necessary
steps involved for me in XSD validation using LIBXML2? I'm using the
latest version.

  Check the testSchemas.c whose source is available in the
distribution,
it should be quite easier to understand.

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard  | virtualization library  http://libvirt.org/
[EMAIL PROTECTED]  | libxml GNOME XML XSLT toolkit
http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/


Eric Zurcher
CSIRO Plant Industry
Canberra, Australia
[EMAIL PROTECTED]