あなたが投稿コードでビットをオフに見ていくつかのことがあります。
- あなたが同じノードをロードしようとしたときに、複数回のロードと同じxmlファイルを保存しているが。
- xpathのようなものでノードにアクセスしようとしていますが、ProcessingのXMLライブラリでサポートされているとは思えません。しかし、ネストされたノードをその名前で取得することができます:
XML firstChild = xml.getChild("childTwo");
- 条件は決して満たされません:
if (j < multiZips.length)
です。 j
は、それはあなたがデータを保存するかは不明だ
901
より
>
ある
1000
から
1900
に行きます。
あなたはカンマで値を連結したいとノードのコンテンツとして、あなたがこのような何かを行うことができますことを設定した場合:
:
XML xml;
int start = 1000;
int end = 1901;
int[] multiZips = new int[end- start];
for (int i = start; i < end; i++) {
multiZips[i-start] = i;
}
//load the XML once
xml = loadXML("sample.xml");
//get a reference to the child you want to append to
XML firstChild = xml.getChild("childTwo");
//create a string to concatenate to
String zips = "";
for (int j : multiZips) {
String zip = str(j);
//append to string
zips += (zip + ", ");
}
//add the concatenated string
firstChild.setContent(zips);
//save once
saveXML(xml, "sample.xml");
あなたは個々のノードを保存したい場合は、あまりにもそれを行うことができます
XML xml;
int start = 1000;
int end = 1901;
int[] multiZips = new int[end- start];
for (int i = start; i < end; i++) {
multiZips[i-start] = i;
}
//load once
xml = loadXML("sample.xml");
//get a reference to <childtwo>
XML firstChild = xml.getChild("childTwo");
for (int j : multiZips) {
String zip = str(j);
//create a new node (in this case we'll call it zip, but it can be something else)
XML newNode = new XML("zip");
//set the value as it's content
newNode.setContent(zip);
//append the new node to the <childTwo> node
firstChild.addChild(newNode);
}
//save once
saveXML(xml,"sample.xml");
なぜこのループを再利用すれば2回繰り返すのかはっきりしません:for (int i = start; i < end; i++)
でもXMLコンテンツを追加できます。
希望の結果は良いでしょう、あなたの質問は何ですか? –