-1

I have a problem. Can't name XAttribute like this: XAttribute("xmlns", nss.NamespaceName)

XNamespace ns = "urn:hl7-org:v3"; XNamespace nsVoc = "urn:hl7-org:v3/voc";

 new XElement("ClinicalDocument",
              new XAttribute(XNamespace.Xmlns + "xsi", xsiNs.NamespaceName),
              new XAttribute("xmlns", nss.NamespaceName),
              new XAttribute(XNamespace.Xmlns + "voc", nsVoc.NamespaceName),
              new XAttribute(xsiNs + "schemaLocation", ns.NamespaceName + "../Schemas/cda/Schemas/CDA.xsd"), 
 new XElement("typeId",
              new XAttribute("root", rootTypeId),
              new XAttribute("extension", extensionTypeId)),
 new XElement("templateId",
              new XAttribute("root", rootTemplateId)),
              new XElement("templateId",
              new XAttribute("root", rootTemplatedId)),

. . .

i dont close this parent nod here.. I have 2000 lines betwean end nod

THE MESSAGE IS: The prefix '' cannot be redefined from '' to 'urn:hl7-org:v3' within the same start element tag.

pnuts
  • 58,317
  • 11
  • 87
  • 139

1 Answers1

0

Instead of

new XElement("ClinicalDocument",
              new XAttribute(XNamespace.Xmlns + "xsi", xsiNs.NamespaceName),
              new XAttribute("xmlns", nss.NamespaceName),

you need

XNamespace df = nss.NamespaceName;
new XElement(df + "ClinicalDocument", 
  new XAttribute(XNamespace.Xmlns + "xsi", xsiNs.NamespaceName),
              new XAttribute(XNamespace.Xmlns + "voc", nsVoc.NamespaceName),
              new XAttribute(xsiNs + "schemaLocation", ns.NamespaceName + "../Schemas/cda/Schemas/CDA.xsd"), 
 new XElement(df + "typeId",

so you need to make sure you create an XNamespace for that default namespace and then your code needs to make sure the new XElement() calls use e.g new XElement(df + "foo") to create the element in the right namespace.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110