Need to remove blank XMLNS attribute from xmldocument

Discussion in 'ASP .Net' started by =?Utf-8?B?RXdhbiBGYWlyd2VhdGhlcg==?=, Apr 14, 2006.

  1. 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
    =?Utf-8?B?RXdhbiBGYWlyd2VhdGhlcg==?=, Apr 14, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RXdhbiBGYWlyd2VhdGhlcg==?=

    [RESEND] Need to remove blank XMLNS attribute from xmldocument

    =?Utf-8?B?RXdhbiBGYWlyd2VhdGhlcg==?=, Apr 18, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    4,020
    Martin Honnen
    Apr 18, 2006
  2. Replies:
    0
    Views:
    1,324
  3. Replies:
    9
    Views:
    62,810
    ChazZeromus
    Feb 25, 2012
  4. Greg Collins [Microsoft MVP]

    Re: How to remove xmlns attribute from XML document (.net)

    Greg Collins [Microsoft MVP], Oct 25, 2006, in forum: XML
    Replies:
    0
    Views:
    825
    Greg Collins [Microsoft MVP]
    Oct 25, 2006
  5. afshar
    Replies:
    3
    Views:
    24,154
    aljar
    May 19, 2010
Loading...

Share This Page