How to retrieve one level of xml only in a loop?

I am processing this xml list:
<item>
     <sponsor></sponsor>
     <itemName></itemName>
     <img></img>
     <description></description>
</item>
<item>
     <sponsor></sponsor>
     <itemName></itemName>
     <img></img>
     <description></description>
     <links>
          <link>
               <thumb></thumb>
               <url></url>
               <caption></caption>
          </link>
          <link>
               <thumb></thumb>
               <url></url>
               <caption></caption>
          </link>
     </links>
</item>
As you can see, only some item nodes have a links node and its related subnodes. 
Originally, my application just had to loop through this collection and add all the "items" nodes to an array:
for each ( var x:XML in myXMLList ) {
     var arr:Array = [];
     for each ( var y:String in x.children()){
          arr.push(y);
     bigArray.push(arr);
Worked fine.  But now I've gotten the rewuirement to handle this potential sub-node "<links>", and now this entire node, tags and all, is getting pushed into "arr".  How would I prevent that, and instead process each "link" node as its own entry in a NEW array?
I am trying to prep this for JSON encoding, btw.  Ulimately I'm looking for:
[ [sponsor,itemname,img,description] , [sponsor,itemname,img,description, [ [link1thumb,link1url,link1caption], [link2thumb,link2url,link2caption]  ]  ]

Use for loop instead for each.
this is your code:
for each ( var x:XML in myXMLList ) {
     var arr:Array = [];
     for each ( var y:String in x.children()){
          arr.push(y);
     bigArray.push(arr);
Instead of above use this
var arr:Array = null;
for(var i:int=0; i< myXMLList.length(); i++){
            arr = new Array();
            if(myXMLList[i].name() != "links"){
             arr.push(myXMLList[i]);
i think it will help.

Similar Messages

  • How to go one level up in xml publisher reports

    Hi Experts,
    I am working in XML Publisher reports; I am working Invoice report (standard report), below is my requirement.
    Template sample:
    <?for-each:G_INVOICE?>
    <?trx_number?> <?trx_type?>
    <?for-each:G_LINES?>
    <?LINE_NUMBER?> <?COMMODITY_CODE?> <?QUANTITY?>
    <?end for-each:G_LINES?>
    <?end for-each:G_INVOICE?>
    Requiremet: If 'trx_type' is INV i want to print commodity_code as COMMODITY_CODE else null.
    I tried like this. It's didn't work out.
    <?for-each:G_INVOICE?>
    <?trx_number?> <?trx_type?>
    <?for-each:G_LINES?>
    <?LINE_NUMBER?> *<?xdofx:if TRX_TYPE='INV' then COMMODITY_CODE else CF_BID_ITEM end if?>* <?QUANTITY?>
    <?end for-each:G_LINES?>
    <?end for-each:G_INVOICE?>
    Here, actually trx_type is in upper loop, it's not checking the TRX_TYPE='INV' condition, it's always going to else part. So I tried like below to go one level up.
    *<?xdofx:if ../TRX_TYPE='INV' then COMMODITY_CODE else CF_BID_ITEM end if?>*
    Still this is also not working. Is there any solutions, where we can use the upper level group field in line level to check the if condition.
    Any suggetion is appreciated.
    Kindly help.
    Thanks in advance.

    To go one level up from current,
    you have to use ../ELEMENT_NAME Since you are trying to access a field in G_LINES context.
    you have to open the xml and see, how may levels are there from G_LINES to G_INVOICE
    if its 2 level up, then use ../../ELEMENT_NAME and likewise.

  • How to retrieve a part of XML document

    Dear Everyone
    I am using
    Oracle: Berkeley DB XML 2.4.16: (October 21, 2008)
    Berkeley DB 4.6.21: (September 27, 2007)
    with python api on mac OSX.
    I want to copy a part of XML document within the document.
    For example, assume that we have the following XML in dbxml.
    <A>
    <B id="1">
    <C>hello</C>
    <D>hi</D>
    </B>
    </A>
    I want to copy <B> with different "id" like,
    <A>
    <B id="1">
    <C>hello</C>
    <D>hi</D>
    </B>
    <B id="2">
    <C>hello</C>
    <D>hi</D>
    </B>
    </A>
    How can I do this?
    One more question. I want to retrieve a part of XML as string.
    For example,
    I want to have a string ' <B id="1"><C>hello</C><D>hi</D></B>'
    How can I do this?
    Thank you very much for your kind help in advance.
    Best regards,
    -Yoshi

    Hi,
    I couldn't add a document like you described:
    dbxml
    dbxml> createC test.dbxml
    dbxml> putD "mydoc" "<C>hello</C><D>hi</D>" "s"
    stdin:5: putDocument failed, Error: Error: XML Indexer: Fatal Parse error in document at line 1, char 13. Parser message: Expected comment or processing instruction (Document: mydoc)
    but, if I fix it and make it well formed it worked, so for
    the experiment I did that:
    dbxml> putD "mydoc" "<mydoc><C>hello</C><D>hi</D></mydoc>" "s"
    Document added, name = mydoc
    I could have added as two separate documents, document 1: <C>hello</C>,
    document 2: <D>hi</D>, but, I don't know what you are trying to do, so
    I'll stick with this example to the first.
    Then I ran a query to show what you did:
    dbxml> query 'collection("test.dbxml")/mydoc/*'
    2 objects returned for eager expression 'collection("test.dbxml")/mydoc/*'
    dbxml> print
    <C>hello</C>
    <D>hi</D>
    I can do the same thing using a query that returns something:
    dbxml> query 'for $i in collection("test.dbxml")/mydoc/* return $i'
    2 objects returned for eager expression 'for $i in collection("test.dbxml")/mydoc/* return $i'
    dbxml> print
    <C>hello</C>
    <D>hi</D>
    This duplicates, but the wrong way:
    dbxml> query 'for $i in collection("test.dbxml")/mydoc/* return ($i,$i)'
    4 objects returned for eager expression 'for $i in collection("test.dbxml")/mydoc/* return ($i,$i)'
    dbxml> print
    <C>hello</C>
    <C>hello</C>
    <D>hi</D>
    <D>hi</D>
    dbxml> query 'for $j in (1,2) for $i in collection("test.dbxml")/mydoc/* return $i'
    4 objects returned for eager expression 'for $j in (1,2) for $i in collection("test.dbxml")/mydoc/* return $i'
    dbxml> print
    <C>hello</C>
    <D>hi</D>
    <C>hello</C>
    <D>hi</D>
    And, finally, for your last string example:
    dbxml> query 'for $i in collection("test.dbxml")/mydoc/C for $j in collection("test.dbxml")/mydoc/D return concat("<C>",$i,"</C>", "<D>", $j, "</D>")'
    1 objects returned for eager expression 'for $i in collection("test.dbxml")/mydoc/C for $j in collection("test.dbxml")/mydoc/D return concat("<C>",$i,"</C>", "<D>", $j, "</D>")'
    dbxml> print
    <C>hello</C><D>hi</D>
    I don't get the 'id' change though.
    I hope this helps.
    -g

  • How to retrieve data from a read-only Excel file

    Hi Developers,
    I'm trying to retrieve data from a read-only Excel file. I used the same code that I used to retrieve data from a normal Excel file, but it can't work.
    My code is as followed:
    try
    InputStream KpExcel = new FileInputStream("kp.xls");
    HSSFWorkbook Kpwb = new HSSFWorkbook(KpExcel);
    HSSFSheet Kpsheet = Kpwb.getSheetAt(0);
    catch(Exception e)
    e.printStackTrace();
    System.out.println("Exception: "+e.getMessage());
    The error I received is as followed:
    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
    at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:224)
    at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:160)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:163)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:210)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:191)
    at photoproductionsystem.IncomingWIPPanel.getKp(IncomingWIPPanel.java:118)
    at photoproductionsystem.IncomingWIPPanel.<init>(IncomingWIPPanel.java:76)
    at photoproductionsystem.TabbedDisplay.<init>(TabbedDisplay.java:47)
    at photoproductionsystem.Display.create(Display.java:73)
    at photoproductionsystem.Display.init(Display.java:44)
    at photoproductionsystem.Display.main(Display.java:229)
    Caused by: java.lang.ArrayIndexOutOfBoundsException
    at java.lang.System.arraycopy(Native Method)
    at org.apache.poi.hssf.record.UnknownRecord.<init>(UnknownRecord.java:62)
    at org.apache.poi.hssf.record.SubRecord.createSubRecord(SubRecord.java:57)
    at org.apache.poi.hssf.record.ObjRecord.fillFields(ObjRecord.java:99)
    at org.apache.poi.hssf.record.Record.fillFields(Record.java:90)
    at org.apache.poi.hssf.record.Record.<init>(Record.java:55)
    at org.apache.poi.hssf.record.ObjRecord.<init>(ObjRecord.java:61)
    ... 15 more
    Can someone please help me with my problem? Thanks a lot in advance!

    Madeline wrote:
    how do I ask at Apache mailing list?I wonder why it seems to be a strange idea to some people to look at the software vendor's site for product support. :p
    http://poi.apache.org/mailinglists.html

  • How to set one layout to display only?

    Hello, Expers,
    I want to display only one layout. The scenario is: when the user input some data in a layout and click on one 'input finish' function button which means that the user has finished input data in that layout, then the system will set that layout to display only. I don't want to use the variable with comparion column because that will also cause all the layout to display only. What I want to do is just set only one layout to display only. Anyone know how to do?

    Dear guqing,
    please take a look at
    http://help.sap.com/saphelp_nw70/helpdata/en/45/9d0fbe42c40063e10000000a11466f/frameset.htm
    http://help.sap.com/saphelp_nw70/helpdata/en/43/174720c5dd3db4e10000000a422035/frameset.htm
    You can use the command SET_INPUT_MODE or SET_DATA_ENTRY_MODE
    Regards
    Matthias Nutt
    SAP Consulting Switzerland

  • How to retrieve value from AIAInstallProperties.xml in AIA Flow.

    After PIP Developement, Installer team will build the OUI installer for the PIP.They will build the screens for our PIP based on the requirements we give them.We give them a list of properties that we need the installer to prompt for and then the installer will store the values entered by the user in AIAInstallProperties.xml file.When the code is written, these properties are used instead of hardcoding any machine names, usernames, passwords, etc. When the services are deployed the properties are replaced with the values in AIAInstallProperties.xml.
    How to retreive those values from AIAInstallProperties.xml file to your participating applications or any adapters in your code?
    When the services are deployed how the properties are getting replaced with the values in AIAInstallProperties.xml.?
    Can anyone explain the above two flow.
    Thanks in advance.

    Hi
    Prem Edwin's posting about AIAInstallProperties.xml is correct.
    Two points, the 11gR1 is a foundation pack only release, that is why the OUI is only built to collect FP related information. In the future, when PIPs arrive, new wizard steps will involve to collect PIP specific information during installation/deployment time.
    For your example of of getting a file location during installation, it would be effectively for your self-built PIPs. That is why the 11gR1 FP OUI would not support that.
    Also, there are only finite number of tokens can be detokenized from AIAInstallProperties.xml to composite.xml, if you were introducing a random new 'file path', I don't believe it would be replaced automatically by default in R1 time.
    Thanks!

  • How to retrieve data from this XML

    Hi
    I am getting below XML file and I need to get data from the file into table in a database ( SQL SERVER ). Please kindly help to shred and load the data into a table 
    <claimInvoice xmlns="http://www.XYZ.com">
      <INum>INum1</INum>
      <dueAmount xmlns="">1</dueAmount>
      <Billadd xmlns="">Billadd1</Billadd>
      <remittance xmlns="">
        <RemCom>RemCom1</RemCom>
      </remittance>
      <summary xmlns="">
        <title>title1</title>   
        <accountAging>
              <totalDue>1</totalDue>
        </accountAging>
    </summary>
    </claimInvoice>
    How Can i get  data for the following :
    INum,
    dueDate,
    Billadd,
    RemCom,
    title,
    totalDue
    Thanks
    Kodi

    see illustration below
    declare @x xml='<claimInvoice xmlns="http://www.XYZ.com">
    <INum>INum1</INum>
    <dueAmount xmlns="">1</dueAmount>
    <Billadd xmlns="">Billadd1</Billadd>
    <remittance xmlns="">
    <RemCom>RemCom1</RemCom>
    </remittance>
    <summary xmlns="">
    <title>title1</title>
    <accountAging>
    <totalDue>1</totalDue>
    </accountAging>
    </summary>
    </claimInvoice>'
    ;WITH XMLNAMESPACES ('http://www.XYZ.com' AS def)
    SELECT t.u.value('def:INum[1]','varchar(50)') AS INum,
    t.u.value('dueAmount[1]','int') AS dueAmount,
    t.u.value('Billadd[1]','varchar(10)') AS Billadd,
    t.u.value('(remittance/RemCom)[1]','varchar(50)') AS RemCom,
    t.u.value('(summary/title)[1]','varchar(50)') AS title,
    t.u.value('(summary/accountAging/totalDue)[1]','int') AS totalDue
    FROM @x.nodes('/def:claimInvoice')t(u)
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to retrieve one of my iTunes playlist?

    I plugged in my friends ipod to synch some music to his ipod like i usually do. When i looked back to find my playlist it disapeared. How to I get this playlist back?

    You can't transfer an acocunt's balance to another account.
    You might be able to re-enable that account via this page : http://appleid.apple.com, then 'reset your password'
    You might then need to log out of your account on your iPad by tapping on your id in Settings > Store (Settings > iTunes & App Store on iOS 6+) and then log back in so as to 'refresh' the account on it
    For the security questions, if you have a rescue email address (which is not the same thing as an alternate email address) set up on your account then the steps half-way down this page should let you reset them : http://support.apple.com/kb/HT5312
    If you don't have a rescue email address (you won't be able to add one until you can answer 2 of your questions) then you will need to contact iTunes Support / Apple to get the questions reset.
    Contacting Apple about account security : http://support.apple.com/kb/HT5699 (you can also use this link i you can't get your account enabled via the above)
    When they've been reset (and if you don't already have a rescue email address) you can then use the steps half-way down the HT5312 link above to add a rescue email address for potential future use

  • How to print one (or more) page only from multipages report?

    Citations from Report Builder Help:
    To print a report from the Runtime Previewer:
    1. In the Runtime Previewer, click <Page Setup> in the toolbar to verify your printer setup.
    2. Click <Print> in the toolbar.
    3. In the dialog box, type the number of pages and copies you want to print.
    If you ran the report with a DESTYPE of Screen, a warning appears that you should run the report with a DESTYPE of Preview before printing. Preview creates PostScript output, which is typically more desirable for printing bit-mapped reports.
    4. Click OK.
    When I click <Print>, the dialog box is not dispaying and all report pages are sending to printer.

    Hi Al,
    Check out this thread: Sort within Break? I was looking to preserve a basic sort for break purposes, but the same solution should work for keeping one row at the bottom.
    Let me know if you'd like more details.
    --Jennifer                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How  to retrieve one row from the number of records in a table

    i want to retrieve the rows from the number of records in a table without using the perticular column name.

    select count(*) from table
    /If you have your table currently analyzed, and no changes have been made, then you could
    select num_rows from user_tables where table_name = 'table'

  • How to retrieve ONE address from Time Capsule backup..

    I found this, after a search, here.. in an archived Discussion-
    "I decided to delete the entry from AddressBook and restore the previous hours' copy of the entire record for that person. It takes less than a minute to restore a record like this.."
    I need to do this!
    can anyone post (very) detailed instructions, please?!
    I lost an important phone number and don't know when I inadvertently erased it.
    I tried entering Time Machine; choosing a year old backup; and looked up Address Book under every heading I could think of (L's hard drive, L's iMac, Applications, etc) but every time I clicked on "Address Book", I simply saw a small screen picture of Address Book, version number.. no individual names or addresses..
    I'd be grateful for help- thank you!

    There is info on address restore here.
    http://pondini.org/TM/15.html
    I am not sure if it is exactly detailed enough.

  • How to retrieve photos from the iCloud

    How to retrieve photos from the iCloud

    icloud only stores photos in backups (or in a special case, when using photo stream).  If you have turned on backup and made sure the camera roll is turned on (only photos from camera roll are backed up), then you can get photos back by performing a restore.  But note that users should always sync photos to a computer to archive them, relying on icloud is not foolproof.
    http://support.apple.com/kb/HT1766?viewlocale=en_US&locale=en_UShttp://www.ipadconverter-mac.com/restore-iphone-from-icloud/
    Go to Settings>General>Reset and tap Erase All Content and Settings.  This will erase your device.  Then you will go through the setup screens again as you did when your device was new, and when given the option, select Restore from iCloud Backup.

  • Retrieving Images Embedded In XML (from rss using xsl)

    I am trying to comsuem and rss feed into my site but i dont seem to see an "image" element in the Item node. can someoen tell me how to retrieve Images Embedded In XML dreamwaever. i am using an xsl fragment on a pap server.
    Doh

    Hi there, I am using a jsp page that takes a xml page from the internet (user defines what page it is) it then takes the xsl feed and transforms the xml with a TransformerFactory object to get the results as an html page, the error is received when the jsp page is called
    Ian

  • HAVE BEEN UNABLE TO RETRIEVE MY OLD LIBRARY OF PHOTOS, ALBUMS AND PROJECTS SINCE DOWNLOADING AN APERTURE 3 SOFTWARE UPDATE TWO DAYS AGO.  THE NEW LIBRARY ONLY HAS A FEW NEW PHOTOS IN ONE FOLDER  PLEASE ADVISE AS HOW TO RETRIEVE OLD APERTURE LIBRARY WITH

    HAVE BEEN UNABLE TO RETRIEVE MY OLD LIBRARY OF PHOTOS, ALBUMS AND PROJECTS SINCE DOWNLOADING AN APERTURE 3 SOFTWARE UPDATE TWO DAYS AGO.  THE NEW LIBRARY ONLY HAS A FEW NEW PHOTOS IN ONE FOLDER
    PLEASE ADVISE AS HOW TO RETRIEVE OLD APERTURE LIBRARY WITH ALL MY PHOTOS, ALBUMS AND PROJECTS

    Find the old Aperture library in the Finder and double click it to launch Aperture with that library set to the default.
    And check your caps look key.  It appears to be stuck.

  • How to retrieve value from xml file

    hi all,
    can somebody pls tell me how to retrieve value from xml file using SAXParser.
    I want to retrieve value of only one tag and have to perform some validation with that value.
    it's urgent .
    pls help me out
    thnx in adv.
    ritu

    hi shanu,
    the pbm is solved, now i m able to access XXX no. in action class & i m able to validate it. The only thing which i want to know is it ok to declare static ArrayList as i have done in this code. i mean will it affect the performance or functionality of the system.
    pls have a look at the following code snippet.
    public class XMLValidator {
    static ArrayList strXXX = new ArrayList();
    public void validate(){
    factory.setValidating(true);
    parser = factory.newSAXParser();
    //all factory code is here only
    parser.parse(xmlURI, new XMLErrorHandler());     
    public void setXXX(String pstrXXX){          
    strUpn.add(pstrXXX);
    public ArrayList getXXX(){
    return strXXX;
    class XMLErrorHandler extends DefaultHandler {
    String tagName = "";
    String tagValue = "";
    String applicationRefNo = "";
    String XXXValue ="";
    String XXXNo = "";          
    XMLValidator objXmlValidator = new XMLValidator();
    public void startElement(String uri, String name, String qName, Attributes atts) {
    tagName = qName;
    public void characters(char ch[], int start, int length) {
    if ("Reference".equals(tagName)) {
    tagValue = new String(ch, start, length).trim();
    if (tagValue.length() > 0) {
    RefNo = new String(ch, start, length);
    if ("XXX".equals(tagName)) {
    XXXValue = new String(ch, start, length).trim();
    if (XXXValue.length() > 0) {
    XXXNo = new String(ch, start, length);
    public void endElement(String uri, String localName, String qName) throws SAXException {                    
    if(qName.equalsIgnoreCase("XXX")) {     
    objXmlValidator.setXXX(XXXNo);
    thnx & Regards,
    ritu

Maybe you are looking for