(svg_code: str)
| 924 | |
| 925 | |
| 926 | def validate_svg_syntax(svg_code: str) -> Tuple[bool, str]: |
| 927 | try: |
| 928 | import xml.etree.ElementTree as ET |
| 929 | |
| 930 | if not svg_code.strip().startswith('<svg'): |
| 931 | return False, "SVG code must start with <svg" |
| 932 | |
| 933 | if not svg_code.strip().endswith('</svg>'): |
| 934 | return False, "SVG code must end with </svg>" |
| 935 | |
| 936 | try: |
| 937 | ET.fromstring(svg_code) |
| 938 | except ET.ParseError as e: |
| 939 | return False, f"XML parsing error: {e}" |
| 940 | |
| 941 | lines = svg_code.split('\n') |
| 942 | for i, line in enumerate(lines, 1): |
| 943 | import re |
| 944 | unquoted_attrs = re.findall(r'(\w+)=([^"\s>]+)', line) |
| 945 | if unquoted_attrs: |
| 946 | return False, f"Line {i} has unquoted attribute values: {unquoted_attrs[0]}" |
| 947 | |
| 948 | return True, "SVG syntax is correct" |
| 949 | |
| 950 | except Exception as e: |
| 951 | return False, f"Validation process error: {e}" |
| 952 | |
| 953 | |
| 954 | def validate_mxgraphxml_syntax(mxgraph_code: str) -> Tuple[bool, str]: |
no outgoing calls
no test coverage detected