469,647 Members | 1,691 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,647 developers. It's quick & easy.

Need to remove blank XMLNS attribute from xmldocument

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 =====
--
Thanks,

Ewan
Apr 14 '06 #1
0 1709

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Shawn | last post: by
2 posts views Thread by Richard | last post: by
1 post views Thread by jens Jensen | last post: by
2 posts views Thread by Lore Leunoeg | last post: by
1 post views Thread by karthikpv | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.