4

I'm using VS2010, C#, .net, and xmlWriter to create xml documents to HL7 CAT-1 specification. There is an attribute, 'sdtc:ValueSet' that must be created in the document. I am unable to write this attribute name, due to invalid character ":".

Here is the actual line of code:

writer.WriteAttributeString("sdtc:valueSet", "OID value");

Does anyone have a solution for creating the attribute, as shown?

Continuing to research, but decided to post this question in hopes of quickly finding a solution.

This question was flagged as a duplicate, incorrectly I am arguing. Existing responses referenced writing an element, or using LINQ. The problem explicitly states Attribute, using xmlWriter. One responder suggested using an overloaded WriteAttributeString method, which solved the problem.

Amit Joshi
  • 14,103
  • 20
  • 72
  • 131
Ken3141
  • 41
  • 1
  • 3

1 Answers1

5

You're using the wrong overload of the WriteAttributeString Method. Use the one that allows you to specify a prefix and an XML namespace:

writer.WriteAttributeString("sdtc", "valueSet", "urn:hl7-org:sdtc", "OID value");
dtb
  • 206,299
  • 34
  • 391
  • 426