2 Replies Latest reply on Apr 25, 2008 2:16 PM by mdrake-Oracle

    DBMS_XMLDOM.makeElement(). ORA-31183: Node type attribute cannot be conver

    user512662
      Hello!
      We migrated our database from Oracle 9.2.0.7 to Oracle 10.2.0.2 recently. However, one of stored procedures, which uses functions of package DBMS_XMLDOM, began to work incorrectly. During it's execution we've got an error:

      ORA-31183: Node type attribute cannot be converted to desired type

      Here is the code of stored procedure:

      procedure INSERT_NODE_ATTR(
      ANODE in DBMS_XMLDOM.DOMNode,
      SATTRNAME in varchar2,
      SVALUE in varchar2,
      BREPLACE in boolean
      )
      as
      LNode DBMS_XMLDOM.DOMNode;
      LAttr DBMS_XMLDOM.DOMAttr;
      begin
      if not DBMS_XMLDOM.isNull(ANODE) then
      LNode := DBMS_XMLDOM.getNamedItem(DBMS_XMLDOM.getAttributes(ANODE), SATTRNAME);
      if DBMS_XMLDOM.isNull(LNode) then
      LAttr := DBMS_XMLDOM.createAttribute(DBMS_XMLDOM.getOwnerDocument(ANode), SATTRNAME);
      DBMS_XMLDOM.setValue(LAttr, SVALUE);
      LAttr := DBMS_XMLDOM.setAttributeNode(DBMS_XMLDOM.makeElement(ANODE), LAttr);
      else
      if BREPLACE then
      DBMS_XMLDOM.setAttribute(DBMS_XMLDOM.makeElement(LNode), SATTRNAME, SVALUE); -- ERROR ARISES HERE
      end if;
      end if;
      end if;
      end;

      What is appear to be incorrect in this code? What is the bypass of this problem?
      Any suggestions would be appreciated.
      Thanks.
        • 1. Re: DBMS_XMLDOM.makeElement(). ORA-31183: Node type attribute cannot be con
          636100
          I have the same error in:
          sys.xmldom.makeelemnt

          Any Suggestions?
          • 2. Re: DBMS_XMLDOM.makeElement(). ORA-31183: Node type attribute cannot be con
            mdrake-Oracle
            If I understand at least the first case correctly you are trying to create a element from an attribute. This is not legal and the DOM implementation in 9.2.x should not have allowed this in the first place

            Basically

            Attribute => Node => Attribute : Legal
            Attribute => Node => Element : Illegal
            Element => Node => Attribute : Illegal
            Element => Node => Element : Legal

            If you were casting an attribute to an element what would you expect to happen to the attribute value.

            If you are trying to make a element with the same name as the attribute you'll need to create a new element (createElement). Assuming you want to presever the value of the attribute you will also need to create a text node (createTextNode) and then set the value of the text node to the value of the attribute and then append the textnode to the element.

            If the objective here is to convert all the attributes in a document to element a XSL or XQuery approach may be better

            -M.