Repository: godot
Issue: XMLParser doesn't conform to the XML specification for elements
Labels: bug,topic:core

### Tested versions

Reproducible in 4.2.1

### System information

Godot v4.2.1.stable - Pop!_OS 22.04 LTS - X11 - Vulkan (Forward+) - integrated Intel(R) Graphics (ADL GT2) () - 12th Gen Intel(R) Core(TM) i5-1235U (12 Threads)

### Issue description

xml_parser.cpp rarely changes, so this issue likely existed in Godot's entire lifetime.

The XML specification defines three types of tags: Start-tags e.g `<svg>`, End-tags e.g. `</svg>`, and Empty-Element Tags e.g. `<svg/>`. The particular syntax is as follows:

**Attributes section:** You have multiple attributes that look like `AttributeName="AttributeValue"`, with a possible arbitrary amounts of whitespace around the equal sign (space, \t, \n, \r) and at the start (at least one is required at the start).

**Tag name:** Can be a bunch of characters, but whitespaces cannot be part of it. This implies that a whitespace should terminate the tag name.

**Start-tag:** `<`, followed by the tag name, followed by an attribute section, followed by an arbitrary amount of whitespace (not required), followed by `>`.

**End-tag:** `</`, followed by the tag name, followed by an arbitrary amount of whitespace (not required), followed by `>`.

**Tag for empty elements:** Exactly like a start-tag, but ends in `/>` instead of `>`.

Relevant section of the specification: https://www.w3.org/TR/REC-xml/#sec-starttags

-----

XMLParser parses certain non-conforming structures, of which some are for sure unintentional. Namely:

- Doesn't seem to consider the validity of tag/attribute names at all.
- Doesn't wait for the final ">" in order to consider something a tag. Doesn't even wait for a name to consider something an end-tag.
- Worst of all and 100% a bug: Whitespace of end-tags gets considered as part of the tag name.

### Steps to reproduce

```gdscript
func _ready():
	var parser = XMLParser.new()
	
	# Example 1: A non-conforming start-tag treated as an element.
	parser.open_buffer("<svg".to_utf8_buffer())
	while parser.read() == OK:
		if parser.get_node_type() == XMLParser.NODE_ELEMENT:
			print("Element")
	
	# Example 2: A non-conforming end-tag treated as an element end.
	parser.open_buffer("</".to_utf8_buffer())
	while parser.read() == OK:
		if parser.get_node_type() == XMLParser.NODE_ELEMENT_END:
			print("Element end")
	
	# Example 3: A non-conforming empty-element tag treated as an element.
	parser.open_buffer("<svg/".to_utf8_buffer())
	while parser.read() == OK:
		if parser.get_node_type() == XMLParser.NODE_ELEMENT:
			print("Element")
	
	# Example 4: Whitespace for end-tags becoming part of the tag name.
	parser.open_buffer("</svg   >".to_utf8_buffer())
	while parser.read() == OK:
		if parser.get_node_type() == XMLParser.NODE_ELEMENT_END:
			prints(parser.get_node_name() == "svg   ")
	
	# Example 5: Invalid tag name.
	parser.open_buffer("<42>".to_utf8_buffer())
	while parser.read() == OK:
		if parser.get_node_type() == XMLParser.NODE_ELEMENT:
			prints("Element")
```

### Minimal reproduction project (MRP)

N/A just copy the code I provided into a node script.