D
Dennis
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE database [
<!ELEMENT database (item)*>
<!ELEMENT item (name,sequence)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT sequence (#PCDATA)>
]>
<database>
<item>
<name>YBL014c</name>
<sequence>ATGAGTG</sequence>
</item>
<item>
<name>YBL025w</name>
<sequence>ATGCTGA</sequence>
</item>
</database>
Here's the example I'm working with. When I call
getElementsByName("item"), it returns 2 items as expected. Then when I
call getChildNodes, it returns a NodeList of length 5 for some reason,
even though there are only two child nodes per item? Two of them are
the "name" and "sequence" nodes, and 3 of them are "#text". Plus,
getting to the node values in the "name" and "sequence" nodes is not
completely intuitive. I can get to them, but the method calls seem
weird. (i.e. code below for tempName and tempSeq). If there were more
than two nodes in each "item", how would I get to it, since in this
example I'm coming at the values from opposite sides?
Oh, I'm using the DocumentBuilderFactory -> DocumentBuilder -> Document
- XML Parser from the javax.xml.parsers package.
In my code: nl is a NodeList from getElementsByTagName("item");
....
Node temp = nl.item(i);
NodeList tl = temp.getChildNodes();
Node tn = nl.item(i);
tempName =
tn.getFirstChild().getNextSibling().getFirstChild().getNodeValue();
tempSeq =
tn.getLastChild().getPreviousSibling().getFirstChild().getNodeValue();
....
Dennis
<!DOCTYPE database [
<!ELEMENT database (item)*>
<!ELEMENT item (name,sequence)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT sequence (#PCDATA)>
]>
<database>
<item>
<name>YBL014c</name>
<sequence>ATGAGTG</sequence>
</item>
<item>
<name>YBL025w</name>
<sequence>ATGCTGA</sequence>
</item>
</database>
Here's the example I'm working with. When I call
getElementsByName("item"), it returns 2 items as expected. Then when I
call getChildNodes, it returns a NodeList of length 5 for some reason,
even though there are only two child nodes per item? Two of them are
the "name" and "sequence" nodes, and 3 of them are "#text". Plus,
getting to the node values in the "name" and "sequence" nodes is not
completely intuitive. I can get to them, but the method calls seem
weird. (i.e. code below for tempName and tempSeq). If there were more
than two nodes in each "item", how would I get to it, since in this
example I'm coming at the values from opposite sides?
Oh, I'm using the DocumentBuilderFactory -> DocumentBuilder -> Document
- XML Parser from the javax.xml.parsers package.
In my code: nl is a NodeList from getElementsByTagName("item");
....
Node temp = nl.item(i);
NodeList tl = temp.getChildNodes();
Node tn = nl.item(i);
tempName =
tn.getFirstChild().getNextSibling().getFirstChild().getNodeValue();
tempSeq =
tn.getLastChild().getPreviousSibling().getFirstChild().getNodeValue();
....
Dennis