2

I am using Oracle 11g and I try to create XML data. One of the tags is:

<majorLine>

I use the below code to generate it:

l_major_line := DBMS_XMLDOM.createElement (l_domdoc, 'ns1:majorLine');  

DBMS_XMLDOM.setattribute (l_major_line, 'xmlns:ns1','urn:xyz:ccw:config:msa:data');
DBMS_XMLDOM.setattribute (l_major_line, 'lineId', l_line_id);

It gives this output:

<ns1:majorLine xmlns:ns1="urn:xyz:ccw:config:msa:data"  linId = "12345">

The issue is, that I don't want the portion: "xmlns:ns1="urn:xyz:ccw:config:msa:data"

Instead I need:

<ns1:majorLine linId = "12345">

Please help. Thanks in advance.

3
  • I'm not all sure what your question is. Can you add some more detail? Commented Mar 30, 2015 at 19:16
  • Hi Kevinsky, am using a domnode approach for creating and XML data.One of the tags is <majorline> Commented Mar 30, 2015 at 19:20
  • Hi Kevinsky, i edited the question , Pls let me know if you get any question Commented Mar 30, 2015 at 19:33

1 Answer 1

1

Use dbms_xmldom.removeAttribute:

declare
  l_domdoc dbms_xmldom.DOMDocument;
  l_major_line dbms_xmldom.DOMElement;
  l_node dbms_xmldom.DOMNode;
  l_attrs dbms_xmldom.DOMNamedNodeMap;
  l_len pls_integer;
  l_name varchar2( 4000 );
  l_clob clob;
begin
  -- Sample data preparation.
  l_domdoc := dbms_xmldom.createDocument( 'xmlns:ns1', 'doc' );
  l_major_line := dbms_xmldom.createElement( l_domdoc, 'ns1:majorLine' );
  dbms_xmldom.setAttribute( l_major_line, 'lineId', 12345 );
  dbms_xmldom.setAttribute( l_major_line, 'xmlns:ns1', 'urn:xyz:ccw:config:msa:data' );

  -- Remove exact namespace.
  --dbms_xmldom.removeAttribute( l_major_line, 'xmlns:ns1' );

  -- Or remove generic namespace if the exact name is not known.
  l_node := dbms_xmldom.makeNode( l_major_line );
  l_attrs := dbms_xmldom.getAttributes( l_node );
  l_len := dbms_xmldom.getLength( l_attrs );
  for i in 1 .. l_len loop
    l_node := dbms_xmldom.item( l_attrs, i );
    l_name := dbms_xmldom.getNodeName( l_node );
    if lower( l_name ) like 'xmlns:%' then
      dbms_xmldom.removeAttribute( l_major_line, l_name );
    end if;
  end loop;

  -- Output.
  l_node := dbms_xmldom.makeNode( l_major_line );
  dbms_lob.createTemporary( l_clob, true );
  dbms_xmldom.writeToClob( l_node, l_clob );
  dbms_output.put_line( l_clob );
end;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.