I want to make my XML as such:
<parentItem>
<childItem attribute="myAttribute">myContent</childItem>
</parentItem>
I thought I could just do this:
objXMLWriter.WriteElementString("childItem", "myContent")
objXMLWriter.WriteAttributeString("attribute", "myAttribute")
But...I get an error. And I found this that explains why:
http://weblogs.asp.net/sonukapoor/pages/204572.aspx
However, it only explains why it happens, not how to actually do what I
want. From what I can tell, WriteAttributeString can ONLY be applied to a
WriteStartElement. Not a WriteElementString.
So, as such, how does one do the above example where I want to add both an
attribute and content to an element?
-Darrel
Martin Honnen - 29 Mar 2007 18:04 GMT
> I want to make my XML as such:
>
> <parentItem>
> <childItem attribute="myAttribute">myContent</childItem>
> </parentItem>
xmlWriter.WriteStartElement("parentItem");
xmlWriter.WriteStartElement("childItem");
xmlWriter.WriteAttributeString("attribute", "myAttribute");
xmlWriter.WriteString("myContent");
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
darrel - 29 Mar 2007 19:55 GMT
> xmlWriter.WriteStartElement("parentItem");
> xmlWriter.WriteStartElement("childItem");
> xmlWriter.WriteAttributeString("attribute", "myAttribute");
> xmlWriter.WriteString("myContent");
> xmlWriter.WriteEndElement();
> xmlWriter.WriteEndElement();
That seems so obvious once you see it. Thanks!
-Darrel