开发者

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, thank开发者_Python百科s!

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

<img src="path" />


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.


Well it's absolutely right - you can't have a space in an XML element name, or indeed in an HTML element name. Why do you think you need it? Image tags don't have spaces in the element name...

Are you sure you don't want to put the space in an attribute value?

Could you give us an example?

EDIT: Okay, so in your comment you want something like:

<img src="path" />

Here:

  • img is the element name
  • src is an attribute name
  • path is an attribute value

So you'd use something like:

writer.WriteStartElement("img");
writer.WriteAttributeString("src", "path");
// Any extra bits you wanted
writer.WriteEndElement();


An element name must follow very strict rules. It must follow the less-then sign < (after which NO space may occur). Then the first character cannot be a dash, a dot or a number (and some others). Finally the rest of the name follows which may include dashes or dots.

The name is further restricted for XML + Namespaces.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜