We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › proXML getElement string !=
Page Index Toggle Pages: 1
proXML getElement string != ? (Read 513 times)
proXML getElement string != ?
Jan 10th, 2006, 8:30am
 
Hi people,

To get elements from xml I wrote a recursive function. But when comparing the getElement return value with the nodename I 'm looking for it always returns false. It does work with nodes created from within p55 however.
Code:
import proxml.*;
XMLElement xBse;
XMLInOut xmlInOut;
void setup() {
try {
xmlInOut = new XMLInOut(this);
xBse = xmlInOut.loadElementFrom("http://www.sjeiti.com/");
} catch(InvalidDocumentException ide) {
println("File does not exist");
}
//
//
XMLElement xUol = new XMLElement("ul");
xBse.addChild(xUol);
//
//
Vector vXML = getXML(xBse,"ul",-1,new Vector(0));
println("uls "+vXML.size());
for (int i=0; i<vXML.size(); i++) {
Vector vUls = getXML((XMLElement)vXML.elementAt(i),"li",-1,new Vector(0));
println("ul "+i+" "+vUls.size());
}
}

Vector getXML(XMLElement xXML, String sName, int iDepth, Vector vReturn) {
if (iDepth>0) iDepth = iDepth-1;
for (int i=0;i<xXML.countChildren();i++) {
XMLElement xNode = xXML.getChild(i);
if (!xNode.isPCDATA()) {
String sNme = xNode.getElement();
println(sNme+"=="+sName+" "+((sNme)==(sName))+" ____ ");
if (xNode.getElement()==sName) {
vReturn.add(xNode);
}
if (xNode.hasChildren()&&iDepth!=0) vReturn = getXML(xNode,sName,iDepth,vReturn);
}
}
return vReturn;
}

As you can see in the printlines... the only "ul"=="ul" is the one I added in p55.
Is there some String thing I don't know about.

gr

Ron
Re: proXML getElement string != ?
Reply #1 - Jan 10th, 2006, 9:21pm
 
i haven't tested the code, but string equality in java is
tested with .equals(). so you should probably replace this:
Code:

if (xNode.getElement()==sName) {
vReturn.add(xNode);
}


with this:
Code:

if (sName.equals(xNode.getElement())) {
vReturn.add(xNode);
}


for a good explanation: http://processing.org/discourse/yabb/YaBB.cgi?action=display;board=Syntax;num=1100632237;start=0#4

Re: proXML getElement string != ?
Reply #2 - Jan 11th, 2006, 2:06am
 
he that's it...
...thanks
Page Index Toggle Pages: 1