Closed danyill closed 1 year ago
No, not recently, at least 40 commits old.
FWIW I discovered this because xmldiff barfed at me when comparing some files:
14:47 $ xmldiff XAT_Prot1_MAC_Updated_SEL_Sub.scd Test_From_ICD_SEL_NR_Initial.scd
Traceback (most recent call last):
File "/usr/bin/xmldiff", line 33, in <module>
sys.exit(load_entry_point('xmldiff==2.4', 'console_scripts', 'xmldiff')())
File "/usr/lib/python3/dist-packages/xmldiff/main.py", line 116, in diff_command
result = diff_files(args.file1, args.file2, diff_options=diff_options,
File "/usr/lib/python3/dist-packages/xmldiff/main.py", line 50, in diff_files
return _diff(etree.parse, left, right,
File "/usr/lib/python3/dist-packages/xmldiff/main.py", line 37, in _diff
right_tree = parse_method(right, parser)
File "src/lxml/etree.pyx", line 3536, in lxml.etree.parse
File "src/lxml/parser.pxi", line 1897, in lxml.etree._parseDocument
File "src/lxml/parser.pxi", line 1917, in lxml.etree._parseFilelikeDocument
File "src/lxml/parser.pxi", line 1811, in lxml.etree._parseDocFromFilelike
File "src/lxml/parser.pxi", line 1201, in lxml.etree._BaseParser._parseDocFromFilelike
File "src/lxml/parser.pxi", line 615, in lxml.etree._ParserContext._handleParseResultDoc
File "src/lxml/parser.pxi", line 725, in lxml.etree._handleParseResult
File "src/lxml/parser.pxi", line 654, in lxml.etree._raiseParseError
File "/home/mulhollandd/Documents/open-scd-testing/Prot1_ICD_Files/Test_From_ICD_SEL_NR_Initial.scd", line 51900
lxml.etree.XMLSyntaxError: Attribute xmlns:esel redefined, line 51900, column 146
Hmmmm I think this may just be a feature of the way OpenSCD serialises the XML and may be quite valid (?). We use XMLSerializer.serializeToString and MDN suggests that non-default namespaces are added on individual elements, not the root element:
For XML serializations, Element and Attr nodes are always serialized with their namespaceURI intact. This may mean that a previously-specified prefix or default namespace may be dropped or altered.
In which case perhaps this can/should be closed.
We discussed this today, and it was suggested that if the namespaces are transferred from the imported document first to the project document and then the nodes are cloned, the namespaces should not be repeated on the imported elements.
The behaviour at the moment is "safe" because it avoids namespace conflicts by only applying the namespace at the point at which it is required (thanks @dlabordus).
I thought I had tried this but was unsuccessful with this approach, but I will provide further information soon.
We agreed the ideally the namespaces would be declared on the root node so it seems the issue remains relevant.
@dlabordus thanks for the discussion this evening (and FYI @ca-d).
I have opened a PR (draft, not for merging) in #1080.
The output from running this with the attached is something like this, which is not what we hoped would occur. Did I get my order of operations incorrect? All gentle mockery gratefully accepted :smile_cat:
My steps are:
<SCL xmlns="http://www.iec.ch/61850/2003/SCL" version="2007" revision="B" release="4" xmlns:esel="http://www.selinc.com/2006/61850">
<Header id="project"/>
<Communication>
<SubNetwork name="W01">
<ConnectedAP iedName="XAT_SEL_411L_2" apName="S1">
<Address>
<P type="IP">0.0.0.0</P>
<P type="IP-SUBNET">255.255.255.0</P>
<P type="IP-GATEWAY">0.0.0.0</P>
<P type="OSI-TSEL">0001</P>
<P type="OSI-PSEL">00000001</P>
<P type="OSI-SSEL">0001</P>
</Address>
<GSE ldInst="CFG" cbName="Ctl">
<Address>
<P type="MAC-Address">01-0C-CD-01-00-00</P>
<P type="APPID">0000</P>
<P type="VLAN-PRIORITY">4</P>
<P type="VLAN-ID">3E8</P>
</Address>
<MinTime unit="s" multiplier="m">4</MinTime>
<MaxTime unit="s" multiplier="m">1000</MaxTime>
</GSE>
</ConnectedAP>
</SubNetwork>
</Communication>
<IED desc="ICD-411L-2S-R001-V0 for firmware R200-V0 or higher" name="XAT_SEL_411L_2" type="SEL_411L_2S" manufacturer="SEL" configVersion="ICD-411L-2S-R001-V0-Z200006-D20210701" originalSclVersion="2007" originalSclRevision="B">
<Private type="SEL_IedInfo">
<esel:ModelNumber xmlns:esel="http://www.selinc.com/2006/61850">SEL-411L-2S</esel:ModelNumber>
<esel:ModelVersionMin xmlns:esel="http://www.selinc.com/2006/61850">R200</esel:ModelVersionMin>
<esel:ClassFileVersion xmlns:esel="http://www.selinc.com/2006/61850">006</esel:ClassFileVersion>
See attached:
I notice we call cloneNode and not importNode as MDN suggests and I do wonder why but perhaps that is a distraction.
Goot point, importNode may just be the fix for this.
Describe the bug
I did the following:
The output looks like:
Namespace declarations appear to be incorrectly.
esel
namespace has a namespace declaration on the element.esel
This is on openscd.github.
I expect the namespace to be registered on the root element and not repeated.
The initial icd file appears correct:
To Reproduce
XAT_SEL-411L-2.ICD.zip
Steps to reproduce the behavior:
I think this must have happened recently...