Search code examples
c#htmlxmlwriter

Cannot use space in XMLElementName


I am using XMLwriter to create HTML which works well, but now I need to place image tag but I am not able to do that - it still reports I cannot use ' ' in the element name. Please advice hwo to solve that, thanks!

EDIT: Basically, how to create in XML document this:

<img src="path" />

Solution

  • It's right, you can't have a space in an XML element name.

    In the case of <img src="path" /> the element name is img, then there's an attribute with a name of src and a value of path. So you don't need a space in your element name, you just need to render the rest of it as an attribute rather than trying to put it all in the element name field.