final int importBinary(XMLElement elem, int offs, ByteBuffer buf, String fieldName) 
        throws XMLImportException
    { 
        if (elem == null || elem.isNullValue()) {
            offs = buf.packI4(offs, -1);
        } else if (elem.isStringValue()) {
            String hexStr = elem.getStringValue();
            int len = hexStr.length();
            buf.extend(offs + 4 + len/2);
            Bytes.pack4(buf.arr, offs, len/2);
            offs += 4;
            for (int j = 0; j < len; j += 2) { 
                buf.arr[offs++] = (byte)((getHexValue(hexStr.charAt(j)) << 4) | getHexValue(hexStr.charAt(j+1)));
            }
        } else { 
            XMLElement ref = elem.getSibling("ref");
            if (ref != null) { 
                buf.extend(offs + 4);
                Bytes.pack4(buf.arr, offs, mapId(getIntAttribute(ref, "id")));
                offs += 4;
            } else { 
                XMLElement item = elem.getSibling("element");
                int len = (item == null) ? 0 : item.getCounter(); 
                buf.extend(offs + 4 + len);
                Bytes.pack4(buf.arr, offs, len);
                offs += 4;
                while (--len >= 0) { 
                    if (item.isIntValue()) { 
                        buf.arr[offs] = (byte)item.getIntValue();
                    } else if (item.isRealValue()) { 
                        buf.arr[offs] = (byte)item.getRealValue();
                    } else {
                        throwException("Conversion for field " + fieldName + " is not possible");
                    }
                    item = item.getNextSibling();
                    offs += 1;
                }
            }
        }
        return offs;
    }