> ------------ Původní zpráva ------------
> Od: Peter Bigot <big...@acm.org>
> Předmět: Re: [pyxb-users] Help with XML generation
> Datum: 03.7.2010 02:32:44
> ----------------------------------------
> It's harder with your schema because the elements are defined within the
> complex types, rather than globally where they can be referenced by their
> element name (as they appear in the document)
> 
> If you want to create the inner elements independently, you can do so using
> their type, as with inv.invoiceHeaderType() below.  Alternatively, you can
> ask PyXB to pick an appropriate type based on the content model, as with the
> assignment to ivh.account below.
> 
> If you want to create them dynamically as parameters to a constructor, you
> can often just provide the value as a keyword parameter; other times you
> might need to use the
> pyxb.BIND<http://pyxb.sourceforge.net/userref_usebind.html#creating-instances-of-anonymous-types>feature.
> 
> I suggest building the document component-by-component, then putting it
> together at the end.  Here's one approach (not complete, but it should give
> the idea):

Peter,
thanks a lot for your quick and really effectual help. I have extended your 
script with all required elements and I'm now able to produce valid XML 
document without having:
pyxb.RequireValidWhenGenerating(False)

Thank you very much. Saved me a lot of time. May I have another two questions?

1. How can I add information about encoding, I'd like to have it utf8.
<?xml version="1.0" encoding="UTF-8"?>

2. How can I work with utf8 characters within my script? It doesn't work for 
me. My test is:
ivh.text = 'Unicode test ěščřžýáíé'

which ends with error:
Traceback (most recent call last):
  File "sf.py", line 20, in ?
    ivh.text = 'Unicode test ěščřžýáíé'
  File "/usr/lib/python2.4/site-packages/pyxb/binding/basis.py", line 62, in 
__setattr__
    return super(_TypeBinding_mixin, self).__setattr__(name, value)
  File "/usr/lib/python2.4/site-packages/pyxb/binding/content.py", line 521, in 
set
    value = self.__elementBinding.compatibleValue(value, 
is_plural=self.isPlural())
  File "/usr/lib/python2.4/site-packages/pyxb/binding/basis.py", line 1339, in 
compatibleValue
    return self.typeDefinition()._CompatibleValue(value, **kw)
  File "/usr/lib/python2.4/site-packages/pyxb/binding/basis.py", line 270, in 
_CompatibleValue
    return cls(value)
  File "/usr/lib/python2.4/site-packages/pyxb/binding/basis.py", line 684, in 
__new__
    args = cls._ConvertArguments(args, kw)
  File "/usr/lib/python2.4/site-packages/pyxb/binding/basis.py", line 662, in 
_ConvertArguments
    norm_str = unicode(cf_whitespace.normalizeString(args[0]))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 13: 
ordinal not in range(128)

Thanks,
David Hrbac

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
pyxb-users mailing list
pyxb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyxb-users

Reply via email to