Click here to Skip to main content
16,004,974 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am running into a road block with xmlwriter in that I am writing an xml file that has to conform to a certain standard for a specific line has a format I can not seem to output correctly using .WriteStartElement() and .WriteAttributeString().

I sure it is a brainfart on my part, but here is the equivalent line I need to output.

<toc:file toc:URI="file:///filename.ice" />



I get that I need .WriteStartElement("toc","file","Insert something"); to get the first part.
The second part, I can not figure out how to get the "toc:" before the "URI="file//..." part.

Any thoughts on what I am missing here?

Thanks.
Posted
Updated 24-Jun-15 9:16am
v3

1 solution

The toc: prefix will be associated with an XML namespace URI - the "Insert something" part of your WriteStartElement call. You need to pass the same URI to the WriteAttributeString method:
C#
const string TocNamespaceUri = "...";

writer.WriteStartElement("toc", "file", TocNamespaceUri);
writer.WriteAttributeString("URI", TocNamespaceUri, "file:///filename.ice");
writer.WriteEndElement();

This will give you a node which looks like:
XML
<toc:file toc:URI="file:///filename.ice" xmlns:toc="..." />

The namespace URI will need to be a specific value - you'll need to check the specification for the file to find out what that is.
 
Share this answer
 
Comments
Maciej Los 24-Jun-15 15:16pm    
+5!
kevin_rf 6-Jul-15 10:32am    
Thanks, that worked perfectly. Sorry for the delay in getting back.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900