Flex: замена узла в объекте XML - PullRequest
0 голосов
/ 25 января 2010

Я просмотрел некоторые похожие посты на эту тему, но не могу понять, как решить мою проблему. Я думаю, это как-то связано с тем фактом, что сегодня понедельник.

Ну, вот и все. у меня есть объект XML, содержащий:

<root>
   <page>
      <text>
         <style properties=""/>
         <label> Text one</label>
      </text>
      <text>
         <style properties=""/>
         <label> Text two</label>
      </text>
   </page>
   <page>
      <text>
         <style properties=""/>
         <label> Text three</label>
      </text>
      <text>
         <style properties=""/>
         <label> Text four</label>
      </text>
   </page>
</root>

И я хочу заменить только узел метки новым. я поместил новые в XMLList, но теперь я застрял в том, как я могу заменить фактические узлы Вот как выглядит XMLList:

<page>
   <text>
      <style properties=""/>
      <label> Replace the first one</label>
   </text>
   <text>
      <style properties=""/>
      <label> Replace the second one</label>
   </text>
</page>
<page>
   <text>
      <style properties=""/>
      <label> Replace the third one</label>
   </text>
   <text>
      <style properties=""/>
      <label> Replace the fourth one</label>
   </text>
</page>

Ответы [ 2 ]

2 голосов
/ 25 января 2010

Простой пример:

// xml = your XML object    
xml.page[0].text[0].label = 'new text';
xml.page[0].text[1].label = 'new text 2';
trace (xml.toXMLString());

возвращается:

<root>
  <page>
    <text>
      <style properties=""/>
      <label>new text</label>
    </text>
    <text>
      <style properties=""/>
      <label>new text 2</label>
    </text>
  </page>
  <page>
    <text>
      <style properties=""/>
      <label>Text three</label>
    </text>
    <text>
      <style properties=""/>
      <label>Text four</label>
    </text>
  </page>
</root>
0 голосов
/ 25 января 2010

Вы можете использовать e4x, чтобы получить XMMList и затем родительскую функцию в цикле или делать то, что вы хотите со списком:

var r:XML=<root>
  <page>
    <text>
      <style properties=""/>
      <label>new text</label>
    </text>
    <text>
      <style properties=""/>
      <label>new text 2</label>
    </text>
  </page>
  <page>
    <text>
      <style properties=""/>
      <label>Text three</label>
    </text>
    <text>
      <style properties=""/>
      <label>Text four</label>
    </text>
  </page>
</root>;

var xl:XMLList=r.page.text.label;
// use the first element of the list
xl[0].parent().label="i do what i want";


var i:int=0;
// or loop over each elment if the list
for each (var xml:XML in xl){
    xml.parent().label=i + " : " + xml.toString();
    i++;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...