❶ c++如何改XML文件的内容
<?xml version="1.0"?><?mso-application progid="Excel.Sheet"?><Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"> <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"> <LastAuthor>Mr.X</LastAuthor> <Created>2011-09-21T08:38:06Z</Created> <LastSaved>2011-09-29T06:00:28Z</LastSaved> <Version>12.00</Version> </DocumentProperties> <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"> <WindowHeight>10005</WindowHeight> <WindowWidth>10005</WindowWidth> <WindowTopX>120</WindowTopX> <WindowTopY>135</WindowTopY> <ProtectStructure>False</ProtectStructure> <ProtectWindows>False</ProtectWindows> </ExcelWorkbook> <Styles> <Style ss:ID="Default" ss:Name="Normal"> <Alignment ss:Vertical="Center"/> <Borders/> <Font ss:FontName="宋体" x:CharSet="134" ss:Size="12"/> <Interior/> <NumberFormat/> <Protection/> </Style> <Style ss:ID="s62"> <Alignment ss:Vertical="Center"/> <Borders/> <Font ss:FontName="宋体" x:CharSet="134" ss:Size="12"/> <Interior/> <NumberFormat/> <Protection ss:Protected="0"/> </Style> <Style ss:ID="s63"> <Alignment ss:Vertical="Center"/> <Borders/> <Interior/> <NumberFormat/> <Protection ss:Protected="0"/> </Style> <Style ss:ID="s64"> <Alignment ss:Horizontal="Center" ss:Vertical="Center"/> </Style> <Style ss:ID="s65"> <Alignment ss:Horizontal="Center" ss:Vertical="Center"/> <Borders/> <Interior/> <NumberFormat/> <Protection ss:Protected="0"/> </Style> </Styles> <Worksheet ss:Name="Page 1"> <Table ss:ExpandedColumnCount="6" ss:ExpandedRowCount="5" x:FullColumns="1" x:FullRows="1" ss:DefaultColumnWidth="54" ss:DefaultRowHeight="14.25"> <Column ss:AutoFitWidth="0" ss:Width="125.25"/> <Column ss:AutoFitWidth="0" ss:Width="111"/> <Column ss:StyleID="s62" ss:AutoFitWidth="0" ss:Width="99"/> <Column ss:AutoFitWidth="0" ss:Width="67.5"/> <Column ss:AutoFitWidth="0" ss:Width="141"/> <Column ss:AutoFitWidth="0" ss:Width="117"/> <Row ss:AutoFitHeight="0"> <Cell ss:StyleID="s64"><Data ss:Type="String">电子监控交通违章公告</Data></Cell> <Cell ss:StyleID="s64"><Data ss:Type="String">号牌号码</Data></Cell> <Cell ss:StyleID="s65"><Data ss:Type="String">号牌类型</Data></Cell> <Cell ss:StyleID="s64"><Data ss:Type="String">违章类型</Data></Cell> <Cell ss:StyleID="s64"><Data ss:Type="String">违章地点</Data></Cell> <Cell ss:StyleID="s64"><Data ss:Type="String">违章时间</Data></Cell> </Row> <Row ss:AutoFitHeight="0"> <Cell ss:Index="2"><Data ss:Type="String">贵E30589</Data></Cell> <Cell ss:StyleID="s63"><Data ss:Type="String">大型汽车</Data></Cell> <Cell><Data ss:Type="String">乱停乱放</Data></Cell> <Cell><Data ss:Type="String">沙井街/北京路</Data></Cell> <Cell><Data ss:Type="String">2004-06-0809:36:29</Data></Cell> </Row> <Row ss:AutoFitHeight="0"> <Cell ss:Index="2"><Data ss:Type="String">贵E30589</Data></Cell> <Cell><Data ss:Type="String">大型汽车</Data></Cell> <Cell><Data ss:Type="String">乱停乱放</Data></Cell> <Cell><Data ss:Type="String">沙井街/北京路</Data></Cell> <Cell><Data ss:Type="String">2004-06-0815:49:58</Data></Cell> </Row> <Row ss:AutoFitHeight="0"> <Cell ss:Index="2"><Data ss:Type="String">贵E30579</Data></Cell> <Cell ss:StyleID="s63"><Data ss:Type="String">大型汽车</Data></Cell> <Cell><Data ss:Type="String">乱停乱放</Data></Cell> <Cell><Data ss:Type="String">沙井街/北京路</Data></Cell> <Cell><Data ss:Type="String">2004-06-0917:44:07</Data></Cell> </Row> <Row ss:AutoFitHeight="0"> <Cell ss:Index="2"><Data ss:Type="String">贵E20798</Data></Cell> <Cell><Data ss:Type="String">大型汽车</Data></Cell> <Cell><Data ss:Type="String">乱停乱放</Data></Cell> <Cell><Data ss:Type="String">沙井街/北京路</Data></Cell> <Cell><Data ss:Type="String">2004-06-1009:14:55</Data></Cell> </Row> </Table> <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel"> <Unsynced/> <Selected/> <Panes> <Pane> <Number>3</Number> <ActiveRow>7</ActiveRow> <ActiveCol>5</ActiveCol> </Pane> </Panes> <ProtectObjects>False</ProtectObjects> <ProtectScenarios>False</ProtectScenarios> <AllowFormatCells/> <AllowSizeCols/> <AllowSizeRows/> </WorksheetOptions> </Worksheet></Workbook>
❷ 如何写个BAT批处理修改XML文件内容
你好的!
echooffset"file=123.xml"set"file_personal=1231.xml"(for/f"tokens=*"%%iin(%file%)do(sets=%%isets=!s:10.32.20.2=10.32.20.220!echo!s!))>%file_personal%
这个放到一个文件夹上
文件名我暂且定义为123.xml
望采纳!
❸ 如何修改xml文件
你选中的是什么?节点、文本、属性?要改的是什么?修改节点、属性、文本?版那我假设选中的权是节点,要改属性值:使用setAttribute()方法可改变已有属性值,或创建一个新属性。下面的代码向 元素添加了名为 “add\" 的新属性(值是 “a\"):x=xmlDoc.getElementsByTagName(“field\");x[0].setAttribute(“add\",“a\"); 使用nodeValue 属性可更改属性节点的值: x=xmlDoc.getElementsByTagName(“field”)[0].
❹ 使用java如何修改某个xml文件中的某项内容
代码如下:import org.jdom.*;import org.jdom.output.*;import org.jdom.input.*;import java.io.*;public class xml{public void toXml() throws JDOMException,IOException{SAXBuilder saxBuilder=new SAXBuilder(false);saxBuilder.setExpandEntities(false);File file = new File("c:\\test.xml");Document doc =saxBuilder.build(new File("c:\\test.xml"));Element elem=doc.getRootElement();//System.out.println(elem.toString());elem.getChild("Collectors").getChild("Collector").getAttribute("HostIP").setValue("192.168.0.1");elem.getChild("Collectors").getChild("Collector").getAttribute("PortID").setValue("100000");Element elem1 = (Element)elem.clone();Document Doc=new Document(elem1);XMLOutputter XMLOut = new XMLOutputter();XMLOut.setEncoding("BIG5");XMLOut.setNewlines(true);file.delete();XMLOut.output(Doc,new FileOutputStream("c:\\test"+".xml"));}public static void main(String args[]){xml x = new xml();try{x.toXml();}catch(Exception e){}}}
❺ 如何用批处理批量修改xml文件的内容
@echoofffor/f"delims=▓tokens=*eol=▓"%%ain(B.xml)do(set"ln=%%a"set"t=!ln!"set"t=!t:BillCode=a!"if"!t!"neq"!ln!"(set"ln=!ln:^<=^^<!"set"ln=!ln:^>=^^>!"echo!ln!>>temp1.tmp))setctr=0for/f"delims=▓tokens=*eol=▓"%%ain(A.xml)do(set"ln=%%a"set"t=!ln!"set"t=!t:BillCode=a!"if"!t!"neq"!ln!"(setread=falseset/actr+=1setctr2=0for/f"delims=▓tokens=*eol=▓"%%bin(temp1.tmp)do(set/actr2+=1if!read!==falseif"!ctr!"=="!ctr2!"(set"ln=%%b"setread=true)))set"ln=!ln:^<=^^<!"set"ln=!ln:^>=^^>!"echo!ln!>>temp2.tmp)del/f/qA.xmlrenametemp2.tmpA.xmldel/f/qtemp1.tmpechoDone.pause
把它放在xml文件旁运行,它会把A.xml中带有bill code关键字的行整行替换成B.xml中对应的一整行。
运行前请做好原文件的备份。
未经允许不得转载:山九号 » 修改xml文件内容|使用java如何修改某个xml文件中的某项内容