[RESEND] 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 =====
 
M

Martin Honnen

Ewan Fairweather wrote:

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.
=== Lab Details Template ====
<LaboratoryDetails>
<Name/>
<LabCode/>
<Contact/>
<Telephone/>
<Address1/>
<Address2/>
<Postcode/>
</LaboratoryDetails>
=== End of Lab Details Template =====

In my view the best approach is the use the right namespace here
directly for the template that is make that
<LaboratoryDetails xmlns="urn:pathology:labtolabPayload">
That way when you later insert/move stuff from the template to the other
document those elements have the proper namespace.

If you can't change the template to use the proper namespace then you
have a lot of more work to do, one way to solve that is to write an XSLT
stylesheet that transforms the nodes from the null namespace to the
intended namespace.
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top