[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 10:16:22 PDT 2023


My thought would be to identify (best case) or write (worst case) an XSLT script which performs the generic XML processing task of
removing xml attributes whose values match the default specified in an associated DTD, or schema

This is listed as an uncompleted task in a project page on web3d site: https://www.web3d.org/x3d/tools/canonical/doc/x3dTools.htm

So the pipeling would be:
Run x3dcf.py script that adds containerField everywhere; then run the xslt script that removes the containerField attributes which match the default -- which is, as been noted, the large majority of them.

Vince Marchetti


> On Nov 1, 2023, at 12:58 PM, Andreas Plesch <andreasplesch at gmail.com> wrote:
> 
> I did take a look at the generator stylesheet but could not get very far.
> X3DUOM has the containerField default information separate from
> fields, so it could not be processed along with the fields. Perhaps a
> static CONTAINERFIELDDEFAULT() class method could work at class init,
> and then be used to check at XML output.
> I tried
> 
> https://linangdata.com/xslt-tester/
> 
> for no-setup fiddling with SaxonJS2. It takes the large X3DUOM xml and
> the large xslt but there is a dependance on the external tooltips xml
> document which I could not get rid of.
> 
> It should be possible to use Python etree or similar to first ingest
> X3DUOM default containerField data, add a class method like above to
> each concrete Node in x3d.py, and then do the same as the awk script.
> 
> -Andreas
> 
> On Wed, 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
> 
> 
> 
> -- 
> Andreas Plesch
> Waltham, MA 02453
> 
> _______________________________________________
> 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