【100分】用VB6 实现XML 文档的修改保存
本帖最后由 fosm0131 于 2012-12-05 09:36:36 编辑 小弟有如下一个XML file,现在想实现功能:利用form1上的textbox 控件里输入数值,并替换xml file中相应的内容(红色字段),最后那部分的矩阵大小需要改变,(现在是21x21,可能需要改成 N×M,N M是任意正的整数).
有哪位大侠可以给点代码或者启示?xml file 有点长,高分重谢!
<?xml version="1.0"?>
<RECIPE_COMPONENT_NEW xmlns:dt="urn:schemas-microsoft-com:datatypes">
<WAFERLAYOUT_COMPONENT>
<DIE_MAP_DATA>
<DIE_PITCH_WIDTH dt:dt="float">15000</DIE_PITCH_WIDTH>
<DIE_PITCH_HEIGHT dt:dt="float">15000</DIE_PITCH_HEIGHT>
<DIE_DEFINITION_SITE_LIST>
<WAFER_POSITION>
<X_COORDINATE dt:dt="float">-75000.0001881031</X_COORDINATE>
<Y_COORDINATE dt:dt="float">75000.0149357803</Y_COORDINATE> </WAFER_POSITION>
<WAFER_POSITION>
<X_COORDINATE dt:dt="float">-60000.0001881031</X_COORDINATE>
<Y_COORDINATE dt:dt="float">60000.0149357803</Y_COORDINATE> </WAFER_POSITION>
<WAFER_POSITION>
<X_COORDINATE dt:dt="float">104999.999811897</X_COORDINATE>
<Y_COORDINATE dt:dt="float">-74999.9850642197</Y_COORDINATE> </WAFER_POSITION>
</DIE_DEFINITION_SITE_LIST>
<GRID_TOP_LEFT>
<X_COORDINATE dt:dt="float">-150000.000188103</X_COORDINATE>
<Y_COORDINATE dt:dt="float">150000.01493578</Y_COORDINATE>
</GRID_TOP_LEFT>
<DIE_ATTRIBUTE_DIMENSION>
<!--Height-->
<ROWS dt:dt="i4">21</ROWS>
<!--Width-->
<COLUMNS dt:dt="i4">21</COLUMNS>
</DIE_ATTRIBUTE_DIMENSION>
<TOP_LEFT_DIE_INDEX>
<!--Column-->
<X_INDEX dt:dt="i4">5</X_INDEX>
<!--Row-->
<Y_INDEX dt:dt="i4">5</Y_INDEX>
</TOP_LEFT_DIE_INDEX>
<FAR_RIGHT_DIE_INDEX>
<!--Column-->
<X_INDEX dt:dt="i4">17</X_INDEX>
<!--Row-->
<Y_INDEX dt:dt="i4">15</Y_INDEX>
</FAR_RIGHT_DIE_INDEX>
<ORIGIN_DIE_INDEX>
<!--Column-->
<X_INDEX dt:dt="i4">10</X_INDEX>
<!--Row-->
<Y_INDEX dt:dt="i4">10</Y_INDEX>
</ORIGIN_DIE_INDEX>
<INNER_DIE>
<INNER_DIE_ROWS dt:dt="i4">1</INNER_DIE_ROWS>
<INNER_DIE_COLUMNS dt:dt="i4">1</INNER_DIE_COLUMNS>
<INNER_DIE_EVENT_LIST>
</INNER_DIE_EVENT_LIST></INNER_DIE>
<ScribeLine>
<WAFER_POSITION_LIST>
<WAFER_POSITION>
<X_COORDINATE dt:dt="float">-60000.0001881031</X_COORDINATE>
<Y_COORDINATE dt:dt="float">60000.0149357803</Y_COORDINATE>
</WAFER_POSITION>
<WAFER_POSITION>
<X_COORDINATE dt:dt="float">-60200.0001881031</X_COORDINATE>
<Y_COORDINATE dt:dt="float">59800.0149357803</Y_COORDINATE>
</WAFER_POSITION>
</WAFER_POSITION_LIST></ScribeLine>
<RETICLE>
<!--1 indicates TRUE and 0 FALSE-->
<IS_ENABLED dt:dt="boolean">0</IS_ENABLED>
<DIE_INDEX>
<!--Column-->
<X_INDEX dt:dt="i4">0</X_INDEX>
<!--Row-->
<Y_INDEX dt:dt="i4">0</Y_INDEX>
</DIE_INDEX>
<DIMENSION>
<!--Height-->
<ROWS dt:dt="i4">1</ROWS>
<!--Width-->
<COLUMNS dt:dt="i4">1</COLUMNS>
</DIMENSION>
<RETICLE_GRID_DIM>
<!--Height-->
<ROWS dt:dt="i4">0</ROWS>
<!--Width-->
<COLUMNS dt:dt="i4">0</COLUMNS>
</RETICLE_GRID_DIM><NOMINAL_FOCUS dt:dt="float">0</NOMINAL_FOCUS>
<NOMINAL_EXPOSURE dt:dt="float">0</NOMINAL_EXPOSURE>
<RETICLE_MODULATION_SET_LIST>
</RETICLE_MODULATION_SET_LIST></RETICLE>
<DIE_MAP_IMAGE_LIST>
<DIE_MAP_IMAGE>
<DIMENSION>
<!--Height-->
<ROWS dt:dt="i4">128</ROWS>
<!--Width-->
<COLUMNS dt:dt="i4">128</COLUMNS>
</DIMENSION>
<INTEGER_RECTANGLE>
<!--x1-->
<LEFT dt:dt="i4">0</LEFT>
<!--y1-->
<TOP dt:dt="i4">0</TOP>
<!--x2-->
<RIGHT dt:dt="i4">1</RIGHT>
<!--y2-->
<BOTTOM dt:dt="i4">1</BOTTOM>
</INTEGER_RECTANGLE>
<INTEGER_POSITION>
<X dt:dt="i4">0</X>
<Y dt:dt="i4">0</Y>
</INTEGER_POSITION><ANCHOR_TYPE dt:dt="string">Center</ANCHOR_TYPE>
<FLOAT_DIMENSION>
<WIDTH dt:dt="float">4.94010000000003</WIDTH>
<HEIGHT dt:dt="float">4.94010000000003</HEIGHT>
</FLOAT_DIMENSION><IMAGE_FILENAME dt:dt="string">DieCornerLowMag.bmp</IMAGE_FILENAME>
</DIE_MAP_IMAGE>
<DIE_MAP_IMAGE>
<DIMENSION>
<!--Height-->
<ROWS dt:dt="i4">128</ROWS>
<!--Width-->
<COLUMNS dt:dt="i4">128</COLUMNS>
</DIMENSION>
<INTEGER_RECTANGLE>
<!--x1-->
<LEFT dt:dt="i4">0</LEFT>
<!--y1-->
<TOP dt:dt="i4">0</TOP>
<!--x2-->
<RIGHT dt:dt="i4">1</RIGHT>
<!--y2-->
<BOTTOM dt:dt="i4">1</BOTTOM>
</INTEGER_RECTANGLE>
<INTEGER_POSITION>
<X dt:dt="i4">0</X>
<Y dt:dt="i4">0</Y>
</INTEGER_POSITION><ANCHOR_TYPE dt:dt="string">Center</ANCHOR_TYPE>
<FLOAT_DIMENSION>
<WIDTH dt:dt="float">6.58000000000811E-02</WIDTH>
<HEIGHT dt:dt="float">6.58000000000811E-02</HEIGHT>
</FLOAT_DIMENSION><IMAGE_FILENAME dt:dt="string">DieCornerHighMag.bmp</IMAGE_FILENAME>
</DIE_MAP_IMAGE>
</DIE_MAP_IMAGE_LIST><DIE_MAP_ANCHORED dt:dt="boolean">1</DIE_MAP_ANCHORED>
<APPLY_USER_DEFINED_DIE_SIZE dt:dt="boolean">0</APPLY_USER_DEFINED_DIE_SIZE>
<USER_DEFINED_GRID_WIDTH dt:dt="float">0</USER_DEFINED_GRID_WIDTH>
<USER_DEFINED_GRID_HEIGHT dt:dt="float">0</USER_DEFINED_GRID_HEIGHT>
<APPLY_SCALE_DEFECT_COORDINATES dt:dt="boolean">0</APPLY_SCALE_DEFECT_COORDINATES>
<APPLY_USER_DEFINED_SAMPLE_CENTER dt:dt="boolean">0</APPLY_USER_DEFINED_SAMPLE_CENTER>
<USER_DEFINED_SAMPLE_CENTER_X dt:dt="float">0</USER_DEFINED_SAMPLE_CENTER_X>
<USER_DEFINED_SAMPLE_CENTER_Y dt:dt="float">0</USER_DEFINED_SAMPLE_CENTER_Y>
<ENABLE_PARTIAL_DIE dt:dt="boolean">0</ENABLE_PARTIAL_DIE>
<PARTIAL_DIE_EDGE_EXCLUSION dt:dt="float">3000</PARTIAL_DIE_EDGE_EXCLUSION>
<DIE_GRID dt:dt="string">0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </DIE_GRID>
<DIE_GRID dt:dt="string">0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 </DIE_GRID>
<DIE_GRID dt:dt="string">0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 </DIE_GRID>
<DIE_GRID dt:dt="string">0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 </DIE_GRID>
<DIE_GRID dt:dt="string">0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 </DIE_GRID>
<DIE_GRID dt:dt="string">0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 </DIE_GRID>
<DIE_GRID dt:dt="string">0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 </DIE_GRID>
<DIE_GRID dt:dt="string">0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 </DIE_GRID>
<DIE_GRID dt:dt="string">0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 </DIE_GRID>
<DIE_GRID dt:dt="string">0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 </DIE_GRID>
<DIE_GRID dt:dt="string">0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 </DIE_GRID>
<DIE_GRID dt:dt="string">0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 </DIE_GRID>
<DIE_GRID dt:dt="string">0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 </DIE_GRID>
<DIE_GRID dt:dt="string">0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 </DIE_GRID>
<DIE_GRID dt:dt="string">0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 </DIE_GRID>
<DIE_GRID dt:dt="string">0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 </DIE_GRID>
<DIE_GRID dt:dt="string">0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 </DIE_GRID>
<DIE_GRID dt:dt="string">0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 </DIE_GRID>
<DIE_GRID dt:dt="string">0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 </DIE_GRID>
<DIE_GRID dt:dt="string">0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </DIE_GRID>
<DIE_GRID dt:dt="string">0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </DIE_GRID> </DIE_MAP_DATA><DEVICE_NAME dt:dt="string">Waferless</DEVICE_NAME>
</DIE_MAP_DATA></WAFERLAYOUT_COMPONENT></RECIPE_COMPONENT_NEW>
[解决办法]
定位节点的语法叫 XPath
函数 SelectNodes(XPath) 取得一批节点
函数 SelectSingleNode(XPath) 取得一个节点
Google 之
XML 中一批节点无特征区分就可以等同对待。
你可以随意替换;或者全面删除旧的节点,然后插入自己新的节点。
[解决办法]
引用xml,代码中loadXML,得到xml对象,剩下的就是selectnodes和selectsinglenode找节点(可用Xpath语法来找),找到后赋给xmlelement对象,对它的值或属性修改了