[x3d-public] x3d.py roundtrip for Metadata nodes in v.3.3 and v.4.0

Vincent Marchetti vmarchetti at kshell.com
Wed Nov 1 08:16:24 PDT 2023


Thank you Andreas, The x3dcf.py module is a useful tool for generating X3D XML encoding for those scenes which require the containerField xml attribute to unambiguously assign XML elements to the different X3D fields of the parent XML element.

I ran an example Python script for generating a MetadataSet node that required containerField for accurat XML encoding and the correct result is in the GeneratedCalendarMetadataWithCF.x3d file attached.

The pertinent accurate encoding is:
------
    <WorldInfo>
      <MetadataSet containerField='metadata' name='birthday' reference='https://www.archives.gov/legislative/features/washington'>
        <MetadataString containerField='metadata' name='calendar' value='"Julian"'/>
        <MetadataInteger containerField='value' name='day' value='11'/>
        <MetadataInteger containerField='value' name='month' value='2'/>
        <MetadataInteger containerField='value' name='year' value='1731'/>
      </MetadataSet>
    </WorldInfo>

-----

Vince Marchetti

-------------- next part --------------
A non-text attachment was scrubbed...
Name: GenerateCalendarMetadataWithCF.py
Type: text/x-python-script
Size: 791 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20231101/1383c745/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GeneratedCalendarMetadataWithCF.x3d
Type: model/x3d+xml
Size: 920 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20231101/1383c745/attachment.x3d>
-------------- next part --------------


> On Nov 1, 2023, at 10:23 AM, Andreas Plesch <andreasplesch at gmail.com> wrote:
> 
> A quick update:
> 
> On Tue, Oct 31, 2023 at 3:49?PM Andreas Plesch <andreasplesch at gmail.com> wrote:
>> 
>> Notes:
>> 
>> x3d.py is autogenerated from X3DUOM:
>> 
>> https://www.web3d.org/x3d/stylesheets/python/python.html#autogeneration
>> https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/stylesheets/X3duomToX3dPythonPackage.xslt
>> 
>> X3DUOM has all necessary containerField default value information.
>> 
>> But the first step may be to modify the stylesheet to generate
>> containerField attributes for all nodes, for simplicity. It looks like
>> the .XML() function would have to have an additional parameter 'field'
>> X3D(indentLevel, syntax, field) for each node.
>> 
>> Postprocessing the generated XML is not possible since information was
>> irretrievably lost. But postprocessing the autogenerated x3d.py python
>> code may be possible since xslt is not for everyone.
> 
> As a proof of concept I hacked a short awk (since I know it) script to
> process the latest x3d.py to include containerField support:
> 
> https://github.com/andreasplesch/x3d-python-mod/blob/main/src/cfXML.awk
> 
> It looks for the Concrete Nodes section, adds a field parameter to the
> .XML() output function, adds the containerField attribute to the
> output, and adds the field parameter to the .XML() calls for metadata,
> SFNode and MFNode field processing.
> The awk script is very brittle since it relies on comments in x3d.py
> to find the appropriate lines to modify. The hardest part was to get
> the quoting and escaping correct.
> It generates containerField attributes for all SF/MFNode fields except
> 'children'. Of course, most are unnecessary but filtering
> systematically for defaults would probably require involving X3DUOM
> and the generation stylesheet, similar to other XML related 'fields'
> such as style or class.
> 
> The result is https://raw.githubusercontent.com/andreasplesch/x3d-python-mod/main/x3dcf.py
> 
> The modified python script appears to work as expected by adding the
> appropriate containerField attributes in XML output for all the
> examples I tried.
> Realistically, this is as far as I can go with this but I think it may
> show how containerField support in XML output could be provided with
> x3d.py.
> 
> -Andreas
> 
> _______________________________________________
> x3d-public mailing list
> x3d-public at web3d.org
> http://web3d.org/mailman/listinfo/x3d-public_web3d.org



More information about the x3d-public mailing list