怎样 在指定的节点里添加属性
添加属性可以实现,但是怎样把路径定到指定的路径下呢
我想在part 后面添加一个 P_ARTICLE_PARTNR属性,
XmlDocument xmldoc2 = new XmlDocument();
xmldoc2.Load(PubConStr.pPartItemsXmlName);
XmlElement element2 = xmldoc2.DocumentElement;
element2.SelectNodes("part");
element2.SetAttribute("P_ARTICLE_ERPNR", “test1222222222”);
这段代码添加 到 partsmanagement 节点里面了,我想添加到PART里面
例如:
<?xml version="1.0" encoding="utf-8"?>
<partsmanagement count="1" length-unit="mm" weight-unit="kg" type="EPLAN.PartsManagement" build="136.9" database="MD1M1HYC\EPLAN
ET200S
0
1"
P_ARTICLE_ERPNR=“test1222222222”;
<part P_ARTICLE_PARTTYPE="1" P_ARTICLE_PARTNR="SIE.6ES5710-8MA11" P_ARTICLE_CAN_BE_LINED_UP="0" P_ARTICLE_CERTIFICATE_CE="0" P_ARTICLE_CODELETTER="U" P_ARTICLE_CRAFT_COOLING="0" P_ARTICLE_CRAFT_COOLINGLUBRICANT="0" P_ARTICLE_CRAFT_ELECTRICAL="1"
P_ARTICLE_EXTERNAL_DOCUMENT_8="https://support.industry.siemens.com/cs/ww/it/ps/6ES5710-8MA11">
<freeproperty pos="91" P_ARTICLE_FREE_DATA_VALUE="??_??@ET200S / 2012-06;" />
<variant P_ARTICLE_VARIANT="1" P_ARTICLE_ADJUSTRANGE="0" P_ARTICLE_ASSEMBLY_POS_PLACE_SPREADED="0" P_ARTICLE_CABLELENGTH="0" P_ARTICLE_DOORDEPTH="0" P_ARTICLE_DOORHEIGHT="0" P_ARTICLE_DOORMOUNTINGSPACE="0" P_ARTICLE_DOORWIDTH="0" P_ARTICLE_FLOW="0" P_ARTICLE_INTRINSICSAFETY="0" P_ARTICLE_PANELDEPTH="0" P_ARTICLE_PANELHEIGHT="0" P_ARTICLE_PANELMOUNTINGSPACE="0" P_ARTICLE_PANELWIDTH="0" P_ARTICLE_PLCISBUSCOUPLER="0" P_ARTICLE_PLCISBUSDISTRIBUTOR="0" P_ARTICLE_PLCISCPU="0" P_ARTICLE_PLCISPOWERSUPPLY="0" P_ARTICLE_PLCSTATIONTYPE="ET200S" P_ARTICLE_PLCTYPE="6ES5 710-8MA11" P_ARTICLE_PRESSURE="0" P_ARTICLE_SHORTCIRCUITRESISTANT="0" P_ARTICLE_WIRECROSSSECTION_UNIT="0">
<functiontemplate functiondefcategory="301" functiondefgroup="1" functiondefid="1" hasled="0" hasplugadapter="0" intrinsicsafety="0" pos="1" safetyrelevant="0" terminalfunction="0" />
</variant>
</part>
</partsmanagement>
element2.SelectNodes("part")返回的应该是part的element对象,用这个对象添加属性。
不行啊, P_ARTICLE_ERPNR=“test1222222222”; 这个添加到partsmanagement节点里面去了
有人知道怎么搞吗,为什么不能在part节点下添加属性呢
@男人要爽:
XmlElement element2 = xmldoc2.DocumentElement;
XmlElement element3 = (XmlElemnet)element2.SelectNodes("part")[0];
element3.SetAttribute("P_ARTICLE_ERPNR", “test1222222222”);
@授之以渔: 兄弟,你的这个方法确实可以写入,但是他是在文档的最后面写入的,如图所示
我需要在文件的前面写入,要不然导入到其他软件里面打不开
@授之以渔: 有方法写在前面吗
@授之以渔:
P_ARTICLE_PARTNR="PILZ.777750" P_ARTICLE_ERPNR="在这里写入333333"
我需要写在P_ARTICLE_PARTNR="PILZ.777750" 的属性后面 写入P_ARTICLE_ERPNR=“????”