Need to remove blank XMLNS attribute from xmldocument

G

Guest

Hi,

I'm generating the below XML in c# for an asp.net application

When i've generated this XML the <LaboratoryDetails xmlns=""> element has a
blank xmlns set. How do i either a) remove this attribute or b) prevent it
from happening in the first place.

To generate the xml I've got two template files which i've included at the
bottom of this post. Two xmldocuments are created in my code which load the
two sepearate templates as follows: -
XmlDocument doc = new XmlDocument();
XmlDocument lab = new XmlDocument();
doc.Load("TYPE3_GETLABS_RESPONSE_TEMPLATE.xml");
lab.Load("LabDetails_Template.xml");


The lab details are then generated as follows:
XmlNode node0 = lab.SelectSingleNode("//LaboratoryDetails/Name");
node0.InnerText = myReader["labname"].ToString();

where myReader is a SqlDataReader object.

The lab details are then entered into the doc XmlDocument as follows:
XmlDocumentFragment payloadInsert =
doc.CreateDocumentFragment();
payloadInsert.InnerXml = lab.InnerXml;

XmlNode node =
doc.SelectSingleNode("//payload:AvailableLaboratories", nsm);
node.InsertAfter(payloadInsert, node.LastChild);

So the question is how do i prevent this from setting the xmlns="" attribute?

Any help much appreciated - sample XMl document and templates below: -
==== XML Generated By App ===========

<TYPE3_GETLABS_RESPONSE xmlns="urn:pathology:labtolabPayload"
xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:pathology:labtolabPayload TYPE3_GETLABS_RESPONSE.xsd">
<InternalRouting>
<FromLab>
</FromLab>
<ToLab>
</ToLab>
</InternalRouting>
<AvailableLaboratories>
<LaboratoryDetails xmlns="">
<Name>Leeds</Name>
<LabCode>
</LabCode>
<Contact>
</Contact>
<Telephone>
</Telephone>
<Address1>
</Address1>
<Address2>
</Address2>
<Postcode>
</Postcode>
</LaboratoryDetails>
<LaboratoryDetails xmlns="">
<Name>Wake</Name>
<LabCode>Wake</LabCode>
<Contact>Ewan Fairweather</Contact>
<Telephone>01274 530438</Telephone>
<Address1>22 Wakefield Road</Address1>
<Address2>Wakefield</Address2>
<Postcode>WK3 4RF</Postcode>
</LaboratoryDetails>
</AvailableLaboratories>
</TYPE3_GETLABS_RESPONSE>
===End of XMl Generated By App =====


==Type3_GetLabsResponse Template ===
<TYPE3_GETLABS_RESPONSE xmlns="urn:pathology:labtolabPayload"
xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:pathology:labtolabPayload TYPE3_GETLABS_RESPONSE.xsd">

<InternalRouting>
<FromLab></FromLab>
<ToLab></ToLab>
</InternalRouting>
<AvailableLaboratories>
</AvailableLaboratories>
</TYPE3_GETLABS_RESPONSE>
=== End of Type3 Template =====

=== Lab Details Template ====
<LaboratoryDetails>
<Name/>
<LabCode/>
<Contact/>
<Telephone/>
<Address1/>
<Address2/>
<Postcode/>
</LaboratoryDetails>
=== End of Lab Details Template =====
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top