Estoy creando un nuevo XDocument de una tabla. Debo validar el documento de un documento XSD y sigue fallando porque agrega xmlns = "" a uno de los Elementos cuando no debería. Aquí hay partes del código que son pertinentes.XElement agrega automáticamente xmlns = "" a sí mismo
XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
XNamespace xmlns = "https://uidataexchange.org/schemas";
XElement EmployerTPASeparationResponse = null;
XElement EmployerTPASeparationResponseCollection = new XElement(xmlns + "EmployerTPASeparationResponseCollection", new XAttribute(XNamespace.Xmlns + "xsi", xsi), new XAttribute(xsi + "schemaLocation", "https://uidataexchange.org/schemas SeparationResponse.xsd"));
XDocument doc = new XDocument(
new XDeclaration("1.0", null, "yes"), EmployerTPASeparationResponseCollection);
//sample XElement populate Element from database
StateRequestRecordGUID = new XElement("StateRequestRecordGUID");
StateRequestRecordGUID.SetValue(rdr["StateRequestRecordGUID"].ToString());
//sample to add Elements to EmployerTPASeparationResponse
EmployerTPASeparationResponse = new XElement("EmployerTPASeparationResponse");
if (StateRequestRecordGUID != null)
{
EmployerTPASeparationResponse.Add(StateRequestRecordGUID);
}
//the part where I add the EmployerTPASeparationResponse collection to the parent
EmployerTPASeparationResponseCollection.Add(EmployerTPASeparationResponse);
El código anterior produce el siguiente archivo xml.
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<EmployerTPASeparationResponseCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://uidataexchange.org/schemas SeparationResponse.xsd" xmlns="https://uidataexchange.org/schemas">
<EmployerTPASeparationResponse xmlns="">
<StateRequestRecordGUID>98761987654321323456109883</StateRequestRecordGUID>
</EmployerTPASeparationResponse>
</EmployerTPASeparationResponseCollection>
Tenga en cuenta el elemento EmployerTPASeparationResponse. Tiene un atributo xmlns vacío. Lo que quiero pasar es simplemente escribir EmployerTPASeparationResponse sin ningún atributo.
el punto es que no quiero que el atributo xmlns en absoluto dentro de la EmployerTPASeparationResponse. ¿Algunas ideas? – Zach
El hecho de que está allí pero con el valor en blanco significa que no está en ningún espacio de nombres (o más bien en blanco). Si elimina el atributo del espacio de nombres (haciendo lo que dije, y según Dustin a continuación), verá que el atributo no estará allí. Aunque la implicación es que esos nodos (y sus hijos a menos que se sobrescriban explícitamente) están en el espacio de nombres de los padres. – Reddog