Uploaded image for project: 'Xerces2-J'
  1. Xerces2-J
  2. XERCESJ-1720

Generate DOM Element with empty namespace using Apache xerces

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.8.1
    • None
    • Documentation

    Description

      I have a requirement to generate an XML which should have empty namespace. An example XML should looks like:

      <name  xmlns:cap="mynamespace">      
         <cap:attributeID>            
            <attribute1 xmlns="" >xxxx</attribute1>            
            <attribute2 xmlns="" >xxxx</attribute2>      
         </cap:attributeID> 
      </name>
      

       
      As mentioned above, I need to add xmlns attribute with empty string. I have tried following ways to achieve it but none of them worked:

      DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder docBuilder;
      docBuilder = docFactory.newDocumentBuilder();
      Document doc = docBuilder.newDocument(); 
      
      element = doc.createElement("attribute1");  // It did not have any namespace. Output becomes as,  <attribute1>xxxx</attribute1>.
      
      element = doc.createElementNS("", "name"); // Output : <attribute1>xxxx</attribute1>
      
      element = doc.createElement("name");
      element.setAttribute("xmlns", "");  // Output : <attribute1>xxxx</attribute1>
      
      element = doc.createElement("name");
      element.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "");
      // Output : <attribute1>xxxx</attribute1>
      

      What is the correct way of adding an empty string as namespace to cater my requirement? Can someone provide guidance on this?

      Thanks,
      Vithursa

      Attachments

        Activity

          People

            Unassigned Unassigned
            Vithursa Vithursa
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: