Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XDK - add attribute

Status
Not open for further replies.

MikeAJ

Programmer
May 22, 2002
108
US
Hi, I'm very new to the PL/SQL XDK toolit. I'm trying to use the toolkit to parse and add attributes to the following xml snippet:
Code:
<merchandise>
   <part partNumber="448316-01" name="PXI-5703"/>
   <tier level="1">
      <group type="Category" name="Cables" displayName="Cables">
         <group type="SubCategory" name="Shielded" displayName="Shielded">
            <part partNumber="285432-01" name="SH68-D1 Cable (1m)"/>
            <part partNumber="285432-02" name="SH68-D1 Cable (2m)"/>
            <part partNumber="285432-05" name="SH68-D1 Cable (5m)"/>
         </group>
         <group type="SubCategory" name="Unshielded" displayName="Unshielded" >
            <part partNumber="284480-01" name="R6868 Cable (1m)"/>
         </group>
      </group>
   </tier>
</merchandise>
I have to read in each partNumber, retrieve the price for that partNumber, and then add a price attribute to that part tag.

I can get all the parts and parse out the partNumber attribute, but I'm having trouble adding the price attribute to the tag I'm in. Here's what I have so far:
Code:
DBMS_XMLPARSER.parsebuffer(xml_parser, xml_in);
xml_dom := DBMS_XMLPARSER.getDocument(xml_parser);

part_node_list := DBMS_XMLDOM.getElementsByTagName(xml_dom, 'part');

FOR i IN 0..DBMS_XMLDOM.getlength(part_node_list) - 1 LOOP
   part_node := DBMS_XMLDOM.item(part_node_list, i);
   node_map  := DBMS_XMLDOM.getAttributes(part_node);
   v_price   := get_price(get_attribute(node_map, 'partNumber'), v_price_list);
   /* Touble Here */
   DBMS_XMLDOM.setAttribute(part_node, 'price', v_price);
END LOOP;

I've also tried to use:
Code:
v_price_attr := dbms_xmldom.createAttribute(xml_dom, 'price');
dbms_xmldom.setValue(v_price_attr, v_price);
v_price_attr := dbms_xmldom.setAttributeNode(v_element, v_price_attr);

but couldn't get it to work.

Any help is much appreciated!

Thanks,
Mike
 
Nevermind, I figured it out. I simply had to cast the part node to a domElement first. Here's what worked for me
Code:
dom_element  := DBMS_XMLDOM.makeElement(part_node);
      
v_price_attr := dbms_xmldom.createAttribute(xml_dom, 'price');
dbms_xmldom.setValue(v_price_attr, v_price);
v_price_attr := dbms_xmldom.setAttributeNode(dom_element, v_price_attr);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top