Bonjour,

Je voudrais lire un fichier binaire, créer une arborescence xml et exporter cette arborescence dans un fichier.

Je voudrais un fichier qui ressemble à ça :
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<DatasetGeneralInformation NameKey="266">
<DSID DSAB="" DSED="6" DSLG="EN" DSNM="101$100$2__.000" DSRD="20201027" DSTL="" ENED="1.1" ENSP="S-100 Part 10a" PRED="1.0" PROF="1" PRSP="INT.IHO.S-101.1.0" RCID="1" RCNM="10"><DSTC><Categorie>14</Categorie><Categorie>18</Categorie></DSTC>
<DSSI CMFX="10000000" CMFY="10000000" CMFZ="100" DCOX="0.0" DCOY="0.0" DCOZ="0.0" NOCN="3362" NOFR="4667" NOIR="140" NOMN="4" NOPN="4075" NOSN="1526" NOXN="3662" />
<ATCS>
<Code ANCD="1" ATCD="verticalDatum" /><Code ANCD="2" ATCD="information" /><Code ANCD="3" ATCD="text" />
<Code ANCD="4" ATCD="maximumDisplayScale" /><Code ANCD="5" ATCD="horizontalPositionUncertainty" /><Code ANCD="6" ATCD="uncertaintyFixed" />
<Code ANCD="7" ATCD="qualityOfHorizontalMeasurement" /><Code ANCD="8" ATCD="scaleValueMinimum" /><Code ANCD="9" ATCD="surveyAuthority" />
<Code ANCD="10" ATCD="surveyDateRange" /><Code ANCD="11" ATCD="dateEnd" /><Code ANCD="12" ATCD="dateStart" /><Code ANCD="13" ATCD="language" />
<Code ANCD="14" ATCD="dataAssessment" /><Code ANCD="15" ATCD="categoryOfTemporalVariation" /><Code ANCD="16" ATCD="featuresDetected" />
<Code ANCD="17" ATCD="significantFeaturesDetected" /><Code ANCD="18" ATCD="leastDepthOfDetectedFeaturesMeasured" />
<Code ANCD="19" ATCD="fullSeafloorCoverageAchieved" /><Code ANCD="20" ATCD="verticalUncertainty" /><Code ANCD="21" ATCD="uncertaintyVariableFactor" />
<Code ANCD="22" ATCD="featureName" /><Code ANCD="23" ATCD="name" /><Code ANCD="24" ATCD="minimumDisplayScale" />
<Code ANCD="25" ATCD="marksNavigationalSystemOf" /><Code ANCD="26" ATCD="valueOfSounding" /><Code ANCD="27" ATCD="waterLevelEffect" />
<Code ANCD="28" ATCD="categoryOfWreck" /><Code ANCD="29" ATCD="status" /><Code ANCD="30" ATCD="defaultClearanceDepth" />
<Code ANCD="31" ATCD="categoryOfObstruction" /><Code ANCD="32" ATCD="depthRangeMinimumValue" /><Code ANCD="33" ATCD="depthRangeMaximumValue" />
<Code ANCD="34" ATCD="expositionOfSounding" /><Code ANCD="35" ATCD="qualityOfVerticalMeasurement" /><Code ANCD="36" ATCD="scaleMinimum" />
<Code ANCD="37" ATCD="techniqueOfVerticalMeasurement" /><Code ANCD="38" ATCD="surfaceCharacteristics" /><Code ANCD="39" ATCD="underlyingLayer" />
<Code ANCD="40" ATCD="natureOfSurface" /><Code ANCD="41" ATCD="elevation" /><Code ANCD="42" ATCD="stationNumber" />
<Code ANCD="43" ATCD="stationName" /><Code ANCD="44" ATCD="tidalStreamPanelValues" /><Code ANCD="45" ATCD="referenceTide" />
<Code ANCD="46" ATCD="referenceTideType" /><Code ANCD="47" ATCD="tidalStreamValue" /><Code ANCD="48" ATCD="orientation" />
<Code ANCD="49" ATCD="orientationValue" /><Code ANCD="50" ATCD="speedMaximum" /><Code ANCD="51" ATCD="timeRelativeToTide" />
<Code ANCD="52" ATCD="natureOfSurfaceQualifyingTerms" /><Code ANCD="53" ATCD="categoryOfSiloTank" /><Code ANCD="54" ATCD="visuallyConspicuous" />
<Code ANCD="55" ATCD="height" /><Code ANCD="56" ATCD="verticalLength" /><Code ANCD="57" ATCD="sectorCharacteristics" />
<Code ANCD="58" ATCD="lightSector" /><Code ANCD="59" ATCD="colour" /><Code ANCD="60" ATCD="lightCharacteristic" /><Code ANCD="61" ATCD="sectorLimit" />
<Code ANCD="62" ATCD="sectorLimitOne" /><Code ANCD="63" ATCD="sectorBearing" /><Code ANCD="64" ATCD="sectorLimitTwo" />
<Code ANCD="65" ATCD="signalGroup" /><Code ANCD="66" ATCD="signalPeriod" /><Code ANCD="67" ATCD="valueOfNominalRange" />
<Code ANCD="68" ATCD="categoryOfLandmark" /><Code ANCD="69" ATCD="function" /><Code ANCD="70" ATCD="categoryOfWaterTurbulence" />
<Code ANCD="71" ATCD="rhythmOfLight" /><Code ANCD="72" ATCD="exhibitionConditionOfLight" /><Code ANCD="73" ATCD="lightVisibility" />
<Code ANCD="74" ATCD="directionalCharacter" /><Code ANCD="75" ATCD="categoryOfHarbourFacility" /><Code ANCD="76" ATCD="categoryOfLight" />
<Code ANCD="77" ATCD="valueOfDepthContour" /><Code ANCD="78" ATCD="categoryOfDumpingGround" /><Code ANCD="79" ATCD="verticalClearanceFixed" />
<Code ANCD="80" ATCD="verticalClearanceValue" /><Code ANCD="81" ATCD="categoryOfRecommendedTrack" /><Code ANCD="82" ATCD="trafficFlow" />
<Code ANCD="83" ATCD="categoryOfGate" /><Code ANCD="84" ATCD="horizontalClearanceOpen" /><Code ANCD="85" ATCD="horizontalClearanceValue" />
<Code ANCD="86" ATCD="categoryOfRestrictedArea" /><Code ANCD="87" ATCD="restriction" /><Code ANCD="88" ATCD="categoryOfBridge" />
<Code ANCD="89" ATCD="categoryOfFogSignal" /><Code ANCD="90" ATCD="categoryOfRadarTransponderBeacon" /><Code ANCD="91" ATCD="radarWaveLength" />
<Code ANCD="92" ATCD="radarBand" /><Code ANCD="93" ATCD="waveLengthValue" /><Code ANCD="94" ATCD="categoryOfPilotBoardingPlace" />
<Code ANCD="95" ATCD="communicationChannel" /><Code ANCD="96" ATCD="categoryOfMilitaryPracticeArea" /><Code ANCD="97" ATCD="nationality" />
<Code ANCD="98" ATCD="beaconShape" /><Code ANCD="99" ATCD="categoryOfSpecialPurposeMark" /><Code ANCD="100" ATCD="colourPattern" />
<Code ANCD="101" ATCD="categoryOfRadarStation" /><Code ANCD="102" ATCD="categoryOfNavigationLine" />
<Code ANCD="103" ATCD="mMSICode" /><Code ANCD="104" ATCD="virtualAISAidToNavigationType" /><Code ANCD="105" ATCD="topmark" />
<Code ANCD="106" ATCD="topmarkDaymarkShape" /><Code ANCD="107" ATCD="buoyShape" /><Code ANCD="108" ATCD="categoryOfCardinalMark" />
<Code ANCD="109" ATCD="categoryOfLateralMark" /><Code ANCD="110" ATCD="inTheWater" /><Code ANCD="111" ATCD="referenceYearForMagneticVariation" />
<Code ANCD="112" ATCD="valueOfAnnualChangeInMagneticVariation" /><Code ANCD="113" ATCD="valueOfMagneticVariation" />
<Code ANCD="114" ATCD="categoryOfTrafficSeparationScheme" />
</ATCS>
<ITCS>
<Code ITCD="SpatialQuality" ITNC="1" /><Code ITCD="NauticalInformation" ITNC="2" /><Code ITCD="ContactDetails" ITNC="3" />
</ITCS>
<IACS>
<Code IACD="SpatialAssociation" IANC="1" /><Code IACD="AdditionalInformation" IANC="2" />
</IACS>
 
</DSID>
 
</DatasetGeneralInformation>

Lorsque je crée mon arborescence xml, si je définit que la balise ATCS doit avoir pour parent la balise DatasetGeneralInformation, tout fonctionne et je récupère bien mon fichier xml.
Mais si je définit que la balise ATCS doit avoir pour parent la balise DSID (comme ci-dessus), ça plante à l'écriture du fichier xml avec l'erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Traceback (most recent call last):
 
  File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\ElementTree.py", line 1080, in _escape_attrib
 
TypeError: argument of type 'NoneType' is not iterable
 
 
During handling of the above exception, another exception occurred:
 
Traceback (most recent call last):
 
  File "D:\Nicolas\Python\S101Reader v2\s101_reader.py", line 1020, in <module>
    s101.export2xml(s101.tree, output)
 
  File "D:\Nicolas\Python\S101Reader v2\s101_reader.py", line 920, in export2xml
    tree.write(f)
 
  File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\ElementTree.py", line 777, in write
 
  File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\ElementTree.py", line 942, in _serialize_xml
 
  File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\ElementTree.py", line 942, in _serialize_xml
 
  File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\ElementTree.py", line 942, in _serialize_xml
 
  File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\ElementTree.py", line 942, in _serialize_xml
 
  File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\ElementTree.py", line 934, in _serialize_xml
 
  File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\ElementTree.py", line 1103, in _escape_attrib
 
  File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\ElementTree.py", line 1058, in _raise_serialization_error
 
TypeError: cannot serialize None (type NoneType)
La fonction d'export :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
def export2xml(self, tree, out):
        with open(out, 'wb') as f:
            tree.write(f)
J'ai essayé de spécifier 'utf-8' dans le write, mais ça ne change rien

Qu'est ce qui cloche? Il y a une combinaison de caractères qui ne va pas quelque part?



Merci,
Nico