-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resume XML parsing after reporting error
- Loading branch information
Showing
8 changed files
with
131 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<AUTOSAR xsi:schemaLocation="http://autosar.org/schema/r4.0 AUTOSAR_00051.xsd" xmlns="http://autosar.org/schema/r4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<AR-PACKAGES> | ||
<AR-PACKAGE> | ||
<SHORT-NAME>Constants</SHORT-NAME> | ||
<ELEMENTS> | ||
<CONSTANT-SPECIFICATION> | ||
<SHORT-NAME>C_HazardSwitchIllumination_IV</SHORT-NAME> | ||
<VALUE-SPEC> | ||
<NUMERICAL-VALUE-SPECIFICATION> | ||
<SHORT-LABEL>C_HazardSwitchIllumination_IV</SHORT-LABEL> | ||
<VALUE>0</VALUE> | ||
</NUMERICAL-VALUE-SPECIFICATION> | ||
</VALUE-SPEC> | ||
</CONSTANT-SPECIFICATION> | ||
<CONSTANT-SPECIFICATION> | ||
<SHORT-NAME>C_TelltaleBrightness_IV</SHORT-NAME> | ||
<VALUE-SPEC> | ||
<NUMERICAL-VALUE-SPECIFICATION> | ||
<SHORT-LABEL>C_TelltaleBrightness_IV</SHORT-LABEL> | ||
<VALUE>FiftyFive</VALUE> | ||
</NUMERICAL-VALUE-SPECIFICATION> | ||
</VALUE-SPEC> | ||
</CONSTANT-SPECIFICATION> | ||
<CONSTANT-SPECIFICATION> | ||
<SHORT-NAME>C_HazardSwitchIllumination_IV</SHORT-NAME> | ||
<VALUE-SPEC> | ||
<NUMERICAL-VALUE-SPECIFICATION> | ||
<SHORT-LABEL>C_HazardSwitchIllumination_IV</SHORT-LABEL> | ||
<VALUE>0</VALUE> | ||
</NUMERICAL-VALUE-SPECIFICATION> | ||
</VALUE-SPEC> | ||
</CONSTANT-SPECIFICATION> | ||
<CONSTANT-SPECIFICATION> | ||
<SHORT-NAME>C_LightSensor_IV</SHORT-NAME> | ||
<VALUE-SPEC> | ||
<NUMERICAL-VALUE-SPECIFICATION> | ||
<SHORT-LABEL>C_LightSensor_IV</SHORT-LABEL> | ||
<VALUE>65535</VALUE> | ||
</NUMERICAL-VALUE-SPECIFICATION> | ||
</VALUE-SPEC> | ||
</CONSTANT-SPECIFICATION> | ||
<CONSTANT-SPECIFICATION> | ||
<SHORT-NAME>C_HazardSwitchIllumination_IV</SHORT-NAME> | ||
<VALUE-SPEC> | ||
<NUMERICAL-VALUE-SPECIFICATION> | ||
<SHORT-LABEL>C_HazardSwitchIllumination_IV</SHORT-LABEL> | ||
<VALUE>0</VALUE> | ||
</NUMERICAL-VALUE-SPECIFICATION> | ||
</VALUE-SPEC> | ||
</CONSTANT-SPECIFICATION> | ||
</ELEMENTS> | ||
</AR-PACKAGE> | ||
</AR-PACKAGES> | ||
</AUTOSAR> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
SwAddrMethod example | ||
""" | ||
import os | ||
import autosar.xml | ||
import autosar.xml.element as ar_element | ||
|
||
|
||
def print_package_stats(package: ar_element.Package, parent: str = "/"): | ||
""" | ||
Prints number of elements in package and sub-packages | ||
""" | ||
print(f'Number of elements in "{parent}{package.name}": {len(package.elements)}') | ||
parent_path = parent + package.name + "/" | ||
for sub_package in package.packages: | ||
print_package_stats(sub_package, parent_path) | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
file_path = os.path.join(os.path.dirname(__file__), 'data', 'xml_with_errors.arxml') | ||
# This file contains an invalid numerical constants as well as two duplicates. | ||
# From the 5 elements in the XML only 2 is successfully placed into the resulting document. | ||
reader = autosar.xml.Reader() | ||
document = reader.read_file(file_path) | ||
for pkg in document.packages: | ||
print_package_stats(pkg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters