Hi Jason,
   Surely it's because you're creating a new <topics> node each time?

With this line:

modulesList[0]..subsection.(@title==contentRowItem2.Subsection).topics
= new XML(<topics />);

I suspect you should only create the new <topics/> node when there
isn't one there already...

HTH,
   Ian

(Wasn't part 1 of this on another list yesterday? :-))




On Tue, Jun 23, 2009 at 11:26 PM, Merrill,
Jason<jason.merr...@bankofamerica.com> wrote:
> I am transforming some XML from a system that comes to me as a fairly
> "flat" format to a new XML in a more hierarchical form that I can use in
> my app. The hierarchy of the new XML is based on the values contained in
> the "flat" xml (as to which nodes things should go under).  I have it
> 90% done, except for the last little bit:
>
> (this is _contentXML)
>
> <xml>
>  <rows>
>    <row>
>      <Module>iBuild</Module>
>      <Subsection>Assumptions</Subsection>
>      <Topic>Starting iRequire</Topic>
>      <Overview>To start iRequire, you will first need to do a few
> things, like create a user name and password.</Overview>
>      <Author>Sanders, Larry</Author>
>      ...etc.
>    </row>
>    <row>
>     <Module>iDeliver</Module>
>    <Subsection>Technical Constraints</Subsection>
>        ...etc.
>
> And I need to get it to look like this:
>
> (this is finalXML)
>
> <module title="iPlan" orderID="5.00000000000000">
>      <subsections>
>        <subsection title="Assumptions">
>          <topics>
>            <topic title="Starting iRequire" author="Merrill, Jason"
> modified="2009-05-01 13:44:29" animationFileName="hello.swf"
> created="2009-05-01 13:43:24" editor="Merrill, Jason">
>              <Overview>Blah</Overview>
>              <Steps>&lt;step&gt;1. This is the first step.2.This is the
> second step.</Steps>
>            </topic>
>            <topic title="Entering Requirements into iRequire"
> author="Merrill, Jason" modified="2009-05-01 13:44:29"
> animationFileName="hello.swf" created="2009-05-01 13:43:24"
> editor="Merrill, Jason">
>              <Overview>Blah</Overview>
>              <Steps>&lt;step&gt;1. This is the first step.2.This is the
> second step.</Steps>
>            </topic>
>            <topic title="Making Assumptions" author="Merrill, Jason"
> modified="2009-05-01 13:44:29" animationFileName="hello.swf"
> created="2009-05-01 13:43:24" editor="Merrill, Jason">
>              <Overview>Blah</Overview>
>              <Steps>&lt;step&gt;1. This is the first step.2.This is the
> second step.</Steps>
>            </topic>
>          </topics>
>        </subsection>
>        <subsection title="Project Information">
>          <topics>
>            <topic title="Making Assumptions"....  etc.
>
>
> So I have all that working so far, except that it only inserts ONE topic
> (1) - the last one if finds that matches the proper module and
> subsection.
>
> Here is my code for creating, finding the right part of the XML and
> inserting topics (though as I mentioned, the problem is it only inserts
> one topic)
>
> for each (var contentRowItem2:XML in _contentXML..row)
> {
>        var moduleName:String =
> stripSharepointPoundTag(contentRowItem2.Module);
>        var topicXML:XML = new XML("<topic />");
>        topicx...@title = contentRowItem2.LinkTitle;
>        topicx...@author =
> stripSharepointPoundTag(contentRowItem2.Author);
>        //..etc
>        topicXML.overview = new XML(<overview />);
>        topicXML.steps = new XML(<steps />);
>        topicXML.overview = contentRowItem2.Overview;
>        //..etc
>
>        var modulesList:XMLList = finalXML..module.(@title ==
> moduleName);
>
> modulesList[0]..subsection.(@title==contentRowItem2.Subsection).topics =
> new XML(<topics />);
>        if (modulesList.length()!= 1)
>        throw new Error("Can't find single module with
> title:"+moduleName);
>
>        var topicsList:XMLList =
> modulesList[0]..subsection.(@title==contentRowItem2.Subsection).topics;
>        if (topicsList.length()!=1)
>        throw new Error("Can't find single subsection with
> title:"+contentRowItem.Subsection);
>
>        topicsList[0].appendChild(topicXML);
> }
>
> This produces this:
>
> <xml>
>  <modules>
>    <module title="iRequire" orderID="0">
>      <subsections>
>        <subsection title="Technical Constraints">
>          <topics>
>            <topic title="Topic 2 from iRequire, Technical Constraints"
> author="Markley, Bill" modified="2009-05-01 13:44:29"
> animationFileName="hello.swf" created="2009-05-01 13:43:24"
> editor="Wade, Sandra">
>              <Overview>Blah blah blah</Overview>
>              <Steps>&lt;step&gt;1. This is the first
> step.&lt;/step&gt;&lt;step&gt;2. This is the second
> step.&lt;/step&gt;</Steps>
>            </topic>
>          </topics>
>        </subsection>
>        <subsection title="Project Information">
>          <topics>
>            <topic title="Topic 1 from iRequire, Project Information"
> author="Merrill, Jason" modified="2009-05-01 13:44:29"
> animationFileName="hello.swf" created="2009-05-01 13:43:24"
> editor="Merrill, Jason">
>              <Overview>Blah blah blah and more blah and even more
> blah</Overview>
>              <Steps>&lt;step&gt;1. This is the first step.2.This is the
> second step.</Steps>
>            </topic>
>          </topics>
>        </subsection>
>        ..etc.
>
> All great, except there are more topic nodes that should be under
> modules.subsections.topics., but there is only one per subtopic.  The
> last part of my script, topicsList[0].appendChild(topicXML),  is
> suspect- but I would think that appendChild would keep adding children,
> not overwrite them in topicsList[0].  Any ideas what is going on here
> and how to fix?  Thanks!
>
>
> Jason Merrill
>
> Bank of  America   Global Learning
> Shared Services Solutions Development
>
> Monthly meetings on the Adobe Flash platform for rich media experiences
> - join the Bank of America Flash Platform Community
>
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to