Read the nodes that have the same value as the subnodes - XML

It is more of a general JAVA / XML problem, but given that it is going into my BlackBerry app I thought I'd see if anyone knows.

Consider a simple XML document:

                    Whatever 1                   Whatever 2               Whatever 3       

Using the standard org.w3c.dom, I can get the nodes in X by the practice...

NodeList fullnodelist = doc.getElementsByTagName ("x");

But if I want to go to the next set of 'e', I try to use something like...

Element element = (Element) fullnodelist.item(0);NodeList nodes = pelement.getElementsByTagName("e");

EXPECTED back '3' nodes (because there are 3 series of 'e'), but it returns '9' - because it gets all entries including the 'e' apperently.

It would be nice in the above case, because I could probably go through and find what I'm looking for. The problem I have is that when the XML file looks like the following:

            whatever              Something Else                    whatever              Something Else            

When I ask 'e' value, it returns 4, instead of (what I want) 2.

I am simply not understand how DOM parsing works? Generally, in the past I used my own XML documents so I name never articles like this, but unfortunately this isn't my XML file and I don't have the choice to work like this.

What I thought I would do, it is write a loop knots "drills down" so that I can combine each node...

  public static NodeList getNodeList(Element pelement, String find)
    {
        String[] nodesfind = Utilities.Split(find, "/");
        NodeList nodeList = null;

        for (int i = 0 ; i <= nodesfind.length - 1; i++ )
        {
            nodeList = pelement.getElementsByTagName( nodesfind[i] );
            pelement = (Element)nodeList.item(i);
        }

        // value of the nod we are looking for
        return nodeList;
    }

.. While if adopted you ' s/e' in the service, he would return the 2 nodes I'm looking (or elements, perhaps I'm using the wrong terminology?). on the contrary, it returns all the 'e' nodes in this node.

Anyway, if anyone is still with me and has a suggestion, it would be appreciated.

Well, there is no doubt that there is a learning curve robust for XML programming. You can take an hour or two and go through one of the tutorials that are circulating on the net. (Like that of w3schools.com.)

Basically, almost everything in XML is a node, the Document that returns the parser. The API for node tells you that you can test the node type you have by calling getNodeType, which returns one of the constants of type node (Node.ELEMENT_NODE, Node.TEXT_NODE, etc..) If necessary, you can then convert the variable to the corresponding interface (element, text, etc.).

Similarly, the API documentation say you for any node, calling getChildNodes (or for an element node or Document getElementsByTagName) will give you a NodeList (a little non-types of nodes in the XML API), while calling getFirstChild and getNextSibling to any node will give you another node (or null ).

Once you learn the API, writing logic of course is not all that hard. For example, if the only 'e' interest tags are those directly under the element root of the document (as shown in your example) you can simply go to them directly:

Vector getTopENodes(Document doc) {  Vector vec = new Vector();  NodeList nodes = doc.getDocumentElement().getChildNodes();  int n = nodes.getLength();  for (int i = 0; i < n; ++i) {    Node node = nodes.item(i);    if (node.getNodeType() == Node.ELEMENT_NODE &&        "e".equals(node.getNodeName()))    {      vec.addElement(node);    }  }  return vec;}

Note that this example does not assume that all children are nodes of element 'e '. the document could have comments, white space or something else that makes it into the DOM as comment, text or any other type of node.

On the other hand, if you want to capture every "e" tag which is directly under the ' tag, no matter the level, then you need to do something a little more complicated (it's on the top of my head - no guarantee):

static class NodeListImp implements NodeList {  private Vector nodes = new Vector();  public int getLength() {    return nodes.size();  }  public Node item(int index) {    return (Node) nodes.elementAt(index);  }  public add(Node node) {    nodes.addElement(node);  }}

NodeList getTargetNodes(Document doc) {  NodeListImp list = new NodeListImp();  getTargetnodes(list, doc.getDocumentElement(), false);  return list;}

void getTargetNodes(NodeListImp list, Node node, boolean parentIsS) {  if (node.getNodeType() == Node.ELEMENT_NODE) {    // node name is tag name for element nodes    String name = node.getNodeName();    if (parentIsS && "e".equals(name)) {      list.add(node);    }    parentIsS = "s".equals(name);    for (Node child = node.getFirstChild();         child != null;         child = child.getNextSibling())    {      getTargetNodes(list, child, parentIsS);    }  }}

I hope that it gets the idea across.

Tags: BlackBerry Developers

Similar Questions

  • SQL to find the grouped rows that have changed their values?

    Hello
    I wonder if it is a pure SQL way do this...?

    I have a table that has a number of columns:
    InsertionDate
    IDENTITY
    Col - has to pass - z - some data.

    the pair (InsertionDate, identity) is unique.

    The lines represent the same values as they change over time, for example:

    Select * from < mytable > by its identity, InsertionDate;
    Balance InsertionDate identity
    10 February 01-1001 - 100
    11 February 01-1001-1
    1001 12 February 01 50
    10 February 01-1002-10
    11 February 01-1002-10
    1002 12 February 01 76


    I want to do the following:

    Select < myTable > from where InsertionDate and the next InsertionDate have a different value for the balance "grouped by" identity and InsertionDate = "10 February 01»;»»
    [I use "grouped by" with great caution - I can't explain in 'Nick sql' without using the misleading grouped by term]

    To produce the output:

    Balance InsertionDate identity
    10 February 01-1001 - 100
    11 February 01-1001-1

    Select < myTable > from where InsertionDate and the next InsertionDate have a different value for the balance "grouped by" identity and InsertionDate = ' 11 February 01»;»»
    Balance InsertionDate identity
    11 February 01-1001-1
    1001 12 February 01 50
    11 February 01-1002-10
    1002 12 February 01 76

    There may be several columns in addition to the balance that should also be checked for changes.

    See you soon,.
    Karl.

    A little misread your reqs:

    with t as (
               select to_date('10-Feb-01','dd-mon-yy') InsertionDate,1001 Identity,-100 Balance from dual union all
               select to_date('11-Feb-01','dd-mon-yy'),1001,1 from dual union all
               select to_date('12-Feb-01','dd-mon-yy'),1001,50 from dual union all
               select to_date('10-Feb-01','dd-mon-yy'),1002,10 from dual union all
               select to_date('11-Feb-01','dd-mon-yy'),1002,10 from dual union all
               select to_date('12-Feb-01','dd-mon-yy'),1002,76 from dual
              )
    select  InsertionDate,
            Identity,
            Balance
      from  (
             select  InsertionDate,
                     Identity,
                     Balance,
                     row_number() over(partition by Identity order by InsertionDate) rn,
                     lead(Balance,1,Balance - 1) over(partition by Identity order by InsertionDate) next_balance
               from  t
            )
      where balance != next_balance
        and rn != 1
      order by Identity,
               InsertionDate
    /
    
    INSERTION   IDENTITY    BALANCE
    --------- ---------- ----------
    11-FEB-01       1001          1
    12-FEB-01       1001         50
    11-FEB-01       1002         10
    12-FEB-01       1002         76
    
    SQL>  
    

    SY.

  • Feed the list component with labels that have only certain values.

    I have to be able to sort out shorter labels in the component 'listHolder.list' by values in 'Fan', 'Herdighet', etc., which will be selected of the other items in the list
    (those who do not need to be fed by XML, but the list items own dataProvider)

    Practical example: displays only the labels in listHolder.list that are connected to the "H1" value in "Herdighet" or "H2" "Herdighet" etc.

    I am fairly new to AS3, so I do not know how to start. I appreciate everything you can give clues.

    Here's the code so far:

    //--------------------------

    var loader: URLLoader = new URLLoader();

    loader.addEventListener (Event.COMPLETE, onLoaded);

    listHolder.list. addEventListener (Event.CHANGE, itemChange);

    function itemChange(e:Event):void {}

    var selectedObj:Object = a [listHolder.listSelectedIndex]

    var xml;

    var a: Array = [];

    function onLoaded(e:Event):void {}

    XML = new XML (e.target.data);

    var it: XMLList = xml. Lauvtre;

    for (var i: uint = 0; i < il.length (); i ++) {}

    listHolder.list.addItem ({.child('Botanisk_navn').toString ()label: it [i]+ "\n"+ "-" + it [i].child('Norsk_navn').toString () "});

    a [i] = {'Fan': it [i].child('Farge').toString (), 'Herdighet': it [i].child('Herdighet').toString (),}

    "Høyde": he [i].child('hoyde').tostring (), "Botanisk_navn": he [i] .one ('Botanisk_n avn') m:System.NET.SocketAddress.ToString (),.

    'Norsk_navn': it [i].child('Norsk_navn').toString (), 'Image': it [i] .child ('image'). toString(),

    {"Blomstring": he [i].child('Blomstring').toString (), "Lysforhold": he [i] .one ('Lily book') m:System.NET.SocketAddress.ToString ()};

    }

    }

    Loader.Load (new URLRequest ("lauvtre.xml"));

    Fusion is a good thing.  The more you have to understand this, easy it all comes together when the lights start to go.

    In regard to the 'a' table... If you look at how values are it is attributed originally, they are attributed to the 'i' value of the index.  So, if the first element that passes the test of H1/H2 is the 10th 'i', it means that 10 of the table value is assigned to the first value you found.  The first 9 values in the table are zero as a result.

    But if you use the method push of the array class.

    a.push ({"Fan": he [i].child('Farge').toString (),... etc...});

    then the item is added to the index of the table rather than the 'i' the next clue.  If a table will have the same number of elements as the list and the list and table will agree in regard to pair them up.

  • Reading the SWF XML file no longer works in offline mode

    We got a few demos using a Flash 'framework' that loads an XML file, which are listed the items to be included in the Flash. These demos are always works well on our Web site, check out an example here .

    The problem is that our guys in charge of the creation and the maintenance of these demos are not able to run them locally as one of the last update of Windows. "" We used the power to open the main html file in a browser, to example"file:///D:/bei/M01/course.html" and see what it looks like and run the script. " We believe that it is a question of OS that we tried on different browsers with the same result. We have a couple of machines where the Windows Update has not executed and opens the main file works well and that the Flash load the XML file and the corresponding files.

    PS. We are aware that we should move from Flash to HTML5

    Please feature ' local disabled - with file system read in Flash Player default access "link below:

    http://fpdownload.Macromedia.com/pub/labs/flashruntimes/shared/air23_flashplayer23_release notes.pdf

  • How to read the printers.xml file snapshot printer?

    Hi I have a printers.xml file but I can't find the number of printed pages

    Hello

    What is your printer? Normally you can print a printer status report and it should show the number of printed pages.

    Kind regards.

  • analysis of the Web.XML using runassembler

    Hi guys

    Whie creation file ear using runassembler command how it will identify a module that contains the jsp and base files it identify the web.xml file and parse the file web.xml

    Please give me some clearification on this

    At the time of creation of the atg project, we specify following

    1. j2eeapplication name
    2. name of the Web application
    3. context root
    4. Server

    This will create the following:

    • /J2EE - Apps / {j2ee application name}/META-INF/application.xml

    application.XML, this will serve as runassebler while creating ears (reading manifest file) to determine the associated web application to this

    J2EE application.

    • /J2EE - Apps / {the j2ee application name} / {the web application name} .war

    {the web application name} .war file will be your jsp, taglibs, web.xml, this war is packed in the ear if no problem analysis is delivered and used in the

    application execution time.

    When reading the manifest file (main or dependent module) if runassebler meets ATG-EAR-Module in the manifest file,.

    MANIFESTO. MF:

    ATG-EAR-Module: {j2eeapplication name}

    then he waits for application.xml at the path/j2ee-apps / {j2eeapplication name} / META-INF. It reads the application.xml file and determine the web application.

    application.XML:

    {the web application name}

    {the web application context root}

    Then he waits for {web app name} to attend the path/j2ee-apps / {name of the j2ee application} and it packs the file. War in the ear.

    I hope that this answer to your query.

  • Only GET records that have the same values of field has the same value in field B

    Have a hard time with below, please help.

    Here's the situation:

    create table cord (identification NUMBER, CM VARCHAR2 (3), PM VARCHAR2 (2));
    insert into string values (1, '002', 'H1');
    insert into string values (2, '006', 'H1');
    insert into string values (3, '004', 'H2');
    insert into string values (4, '006', 'H2');
    insert into string values (5, '004', 'H3');
    insert into string values (6, '004', 'H3');

    I just need to select the folders which, for the SAME value of PM have the same value in CM, in example above, those are recordings with ID (5,6).

    1 and 2 fail because for them CM and PM are different for the same H1, similar on the 3 and 4.

    I don't know if this will help but records are always in 'pairs', which means that there are no cases as

    7. '004' | H4

    8. ' 006' | H4

    9. '005' | H4

    Any ideas are much appreciated.

    Thank you

    See if the following can help...

    select id,cm,pm
        from(
            select t.*
                  ,count(1) over(partition by cm,pm) cnt
                from testt t
            )
        where cnt>1;
    
  • query to view separate lines that have the same values

    Hello

    I have the columns id, addr1, addr2, city and State of coding. I need to know all the coding IDS that have the same addresses and at the same time filter out the same side of the id of the request.

    For example:

    acctid addr1, addr2 City State

    WEF 1 101 101 sd

    1                         101          wef     sd

    WEF 2 101 101 sd

    WEF 3 101 101 sd

    DC 4 102 102 homeless

    From the above data, I want to get filter tier 4 and get lines 1, 2 and 3. How to achieve with a sql query

    Thank you

    Arch

    This has nothing to do with hard... coding is how you test a query without creating the table, so you'd:

    with match_finder AS (SELECT acctid, addr1, addr2, city, State, count (*) OVER (PARTITION BY addr1, addr2, city, province) AS identical_rows)

    OF )

    Select acctid, addr1, addr2, city, province

    of match_finder

    where identical_rows > 1

    /

    and the rest, I'm sure, you can find on your own...

    HTH

  • All channels to HAVE it have the same value

    I use the example for a multichannel AI aiex2.cpp read with mseries NI6280 devices.

    This example works for a lane, but other chains have the same value

    For example: I put 5 Volt on the first string, and then the other channel are 5 Volt too.

    What should I consider in the configuration?

    Hello Beilei,

    I think that you run in theghost of the question.  The other strings that you use are connected to the earth when you connect the first channel to 5V?  If the other channels are floating, they will read the same value as the first string... 5V.

    Steven T.

  • two elements that have the same source

    Hi guys,.

    I am trying to use the display on a Google Map plugin location. As I had this plugin requires two elements that have the same source:

    Article 1 - A text to insert the value (address) in the database. The source of this question would be 'MAP' column.
    2 - Google Map plugin ELEMENT to visualize on the map. The source of this issue should also be "Map" the column that is used to read the address.

    But the problem, as you saw, we can not create a new record if we have two items with the same source. How can I get around this?

    Here is the link to the plugin:

    http://Apex.Oracle.com/pls/Apex/f?p=plugins:LOCATION_MAP:2943553726537511

    Kind regards
    Fateh

    Published by: Fateh July 21, 2011 02:52

    Hi Fateh,

    Tried the plugin you mentioned! Had a preview of your problem.
    >
    I am trying to use the display on a Google Map plugin location. As I had this plugin requires two elements that have the same source
    >
    As your form seems to be running automatic process line processing DML that will obviously give an error if you have two items
    with the same source i.e. 'MAP' that is your database column.
    >
    Article 1 - A text to insert the value (address) in the database. The source of this question would be 'MAP' column.
    >
    I think that this point is already with you as you may have created form based on a Table or form and report based on a Table.
    Leave the source of this article because it's IE card - the database column.
    >
    2 - Google Map plugin ELEMENT to visualize on the map.
    >
    Change the source of this article as:
    Source type: static assignment (value corresponds to the source attribute)
    Source of value or expression:

    &P1_ADDRESS.
    

    Where P1_ADDRESS is the element:
    >
    Article 1 - A text to insert the value (address) in the database. The source of this question would be 'MAP' column.
    >

    I hope that helps!
    Kind regards
    Kiran

  • Two computers share the same wi - fi Modem. When A computer reads a message that is marked as read on two PCs, not allowing computer B see what needs to be read.

    Two computers share the same WI - fi Modem. When A computer reads a message that is marked as read on the two PC, not allowing the B to see what still needs to be read. Email is Thunderbird.
    Please help, thank you for this option online support

    I should add that if you operate the account using Pop then messages can be left on the server without any indication that they have been read. You define each customer to leave them on the server.

    However if you don't know what messages have been read, I know not how will you know which ones to delete and when to do it. Without active maintenance your server could quickly become full.

  • All channels to HAVE it have the same value - NI PCI-6221 and NI PCI-6229

    Hello

    I use the aiex1.cpp example for a multi-channel read with the devices mseries 6221 and 6229.

    This example works for a lane, but other chains have the same value (difference of +-0.001 Volt).

    For example: I put 5 Volt on the first string, and then the other channel are 5 Volt too.

    What should I consider in the configuration?

    Heiko Hello!

    your description looks like the effect you are having 'ghosts '.

    For more information about ghost images and how to get rid of, check out these links:

    http://digital.NI.com/public.nsf/allkb/73CB0FB296814E2286256FFD00028DDF?OpenDocument

    and

    http://digital.NI.com/public.nsf/allkb/C6C7DE575301A379862572DD00480A01?OpenDocument

    Best regards

    Moritz M.

  • How to read the values of the variables of façade in loops without using local variables or property value nodes?

    I know that local variables and nodes of property value are causing a lot of problems.

    But if I read the value of a variable front outside a loop.

    the value is only read once before the start of the loop.

    Changed the front variable values during the iterations of the loop, is invisible.

    How can I solve this problem?


  • Viruses such as the behavior of the Acrobat Reader software. I have a laptop running WIN 7 and kaspersky AV. yesterday when I started my laptop that I see all the icons on my QuickStart bar browser have been changing drive adobe icon and observe also that

    Viruses such as the behavior of the Acrobat Reader software. I have a laptop running WIN 7 and kaspersky AV. yesterday when I started my laptop I see all the icons from the browser on my QuickStart bar have been changed to the adobe reader icon and also observe that many other programs on my desktop have changed to the adobe reader icon. If you click the icon it opens adobe reader. I deleted Adobe reader using Add or remove programs and the icons back to normal. Yet once, I downloaded and installed Adobe reader 11. the problem has resurfaced. then again, I've uninstalled adobe reader software and installed Adobe Reader version 10 with the same question back. I have now uninstalled Adobe Reader. Please advise on how to install a working copy Adobe reader which will not infect or impinge upon other programs in my laptop.

    Hi imoorthy,

    Please follow the troubleshooting steps mentioned in this document KB Application, file icons change in Acrobat/Reader icon.

    Kind regards

    Nicos

  • I have the latest downloadable version of the LR5.  It crashed while it was perceived 1:1 uttered during an import. After a restart of the Win764(), it displays a message that LR has to leave because he cannot read the preview files and it will try to fix

    I have the latest downloadable version of the LR5.  It crashed while it was perceived 1:1 uttered during an import. After a restart of the Win764(), it shows a message that LR has to leave because he cannot read the preview files and it will try to fix it the next time's lance.  I get the same message to another and whenever he throws so I can't launch LR at all now.

    I get the preview of a file has been corrupted somehow.  Is it possible to fix this without having to build a new catalog?

    Use Windows Explorer to open the folder containing your catalog. You will see a folder with the extension .lrdata. You must remove this folder, and then restart the Lightroom. Lightroom will generate a new folder of previews.

Maybe you are looking for

  • How to track the history of the employee in private browsing?

    My employee began to use it to do work unrelated to private browsing search during the day, how will I know what she's doing online if she uses the private browsing? I need to be able to monitor the use of the internet.

  • iPad 2 9.3.1 hide notification on the lock screen Center

    G ' Day, my ipad 2 is currently locked, but the notification center screen shows and cannot be hidden. The chevron is down, opposed to what is expected, I cannot access the password screen, can't do anything with it. It is not completely locked, I ca

  • Can I use the HP Director software (WinXP) on my laptop HP G62-340US (Win7) with HP PSC 1510xi?

    Can I use the HP Director software from my Office WinXP (HP Pavilion 325c) on my laptop HP G62-340US (Win7 64 bit)? If so, the version of the XP software will work on my Win7 64 bit system? I really liked the HP Director functions when I used it on m

  • When I start my computer, I randomly get BSODS!

    Hello So I'm running Windows 7 Ultimate and when I start my computer for the first time the day I get BSOD. I tried to completely reinstall Windows and it still happens. This often happens when I open Chrome (or another browser) and watch YouTube vid

  • Impossible to update Java

    For several months, the automatic updates of Java have failed. When I click to install, I get two instances of the same "Microsoft jscript runtime error: object doesn't support this property or method."  Currently installed version 7 news 45 is based