From Net which XML file u going to parsing
like:
images/tut/basic/parsingxml/example.xml
if u click the above link u got a xml file .
but in urs:
http://rss.cnn.com/rss/edition_world.rss

arams wrote:From Net which XML file u going to parsing
like:
images/tut/basic/parsingxml/example.xml
if u click the above link u got a xml file .
but in urs:
http://rss.cnn.com/rss/edition_world.rss


jhandal7 wrote:[b] bstubbs wrote:
Artur79, did you ever figure out how to solve the missing string?
I'm getting the same results:
Quote:
ExtractedString =
ExtractedInt = 1337
Anyone else getting this, found a solution? Thanks
Hi
I meet the same proplem.
Chnage the xml file from
XML:
<mytag>
anddev.org rulez =)
</mytag>
to
XML:
<mytag>anddev.org rulez =)</mytag>
That works.
Damn, had the same problem. After changing to inline as you said, it works. It is weird imo, valid xml is valid xml.
_________________
---
Dariusz Dwornikowski
[u]I am using SDK 1.0,this code need upgrade?
![]()
thanks

xinwei wrote:hi,i find there is a problem with the following method:
/** Gets be called on the following structure:
* <tag>characters</tag> */
@Override
public void characters(char ch[], int start, int length) {
if(this.in_mytag){
myParsedExampleDataSet.setExtractedString(new String(ch, start, length));
}
}
that: you should define a StringBuffer to obtain data from <tag>characters</tag>,for the characters may contain some blanks, when i try this demo, i got a null with "ExtractedString" .
first define a private varible :Using java Syntax Highlighting
StringBuffer str = new StringBuffer(); then,replace myParsedExampleDataSet.setExtractedString(new String(ch, start, length)); with Parsed in 0.029 seconds, using GeSHi 1.0.8.4
str.append(new String(ch,start,length));
myParsedExampleDataSet.setExtractedString(str.toString());
and in the classarsedExampleDataSet
[/syntax]
- Code: Select all
public String toString(){
return "ExtractedString = " + this.extractedString
+ "nExtractedInt = " + this.extractedInt;
}
should change to
[syntax="java"]
- Code: Select all
public String toString(){
return "ExtractedString = " + this.extractedString.trim()
+ "nExtractedInt = " + this.extractedInt;
}


plusminus wrote:Hello Anthony,
is pretty long ago... so your xml looks like this (simplified):Using xml Syntax Highlighting
<!-- 21 times the same structure... --> <frbny:Key> <frbny:CURR>AUD</frbny:CURR> </frbny:Key> <frbny:Obs OBS_STATUS="A" OBS_CONF="F"> <frbny:OBS_VALUE>0.9069</frbny:OBS_VALUE> </frbny:Obs> <!-- ... "loop" -->Parsed in 0.001 seconds, using GeSHi 1.0.8.4
right
So i would do it like this:
- When entering [font=Lucida Console]<frbny:CURR>[/font] add one new element to the output-list
- When in [font=Lucida Console]characters()[/font] and [font=Lucida Console]this.in_curr_tag == true[/font], get the last element from the list (which is the one just added) and set its String.
- When entering [font=Lucida Console]<frbny:OBS_VALUE>[/font], do nothing, as the most recent element in the list is waiting to get the Double filled.
- When in [font=Lucida Console]characters()[/font] and [font=Lucida Console]this.in_curr_tag == true[/font], fill the Double of the last added Peds in the list.
So, without any testing:Using java Syntax Highlighting
import java.util.ArrayList; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; public class ExampleHandler extends DefaultHandler { // only the relevant tags private boolean in_curr_tag = false; private boolean in_obs_tag = false; private ArrayList<ParsedExampleDataSet> list = new ArrayList<ParsedExampleDataSet>(22); // 22 == capacity public ArrayList<ParsedExampleDataSet> getParsedData(){ return this.list; } @Override public void startDocument() throws SAXException { //nothing to do here } @Override public void endDocument() throws SAXException { //nothing to do here } /* * Gets be called on opening tags like * <tag> * Can provide attribute(s), when xml was like: * <tag attribute="attributeValue">*/ @Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts)throws SAXException{ if(localName.equals("frbny:CURR")){ list.add(new ParsedExampelDataSet()); this.in_curr_tag = true; }else if(localName.equals("frbny:OBS_VALUE")){ this.in_obs_tag = true; } } //Called on closing tags like </tag> @Override public void endElement(String namespaceURI, String localName, String qName) throws SAXException{ if(localName.equals("frbny:CURR")){ this.in_curr_tag = false; }else if(localName.equals("frbny:OBS_VALUE")){ this.in_obs_tag = false; } } /** Gets be called on the following structure: * <tag>characters</tag> */ @Override public void characters(char ch[], int start, int length) { // getLast()-Function is probably not existing, need to do on your own if(this.in_curr_tag){ list.getLast().setExtractedString(new String(ch, start, length)); } if(this.in_obs_tag){ list.getLast().setExtractedDouble(Double.parseDouble(new String(ch, start, length))); } } }Parsed in 0.039 seconds, using GeSHi 1.0.8.4
Regards,
plusminus


dr3as wrote:Using xml Syntax Highlighting
<outertag> − <innertag sampleattribute="innertagAttribute"> <mytag>anddev.org rulez =)</mytag> <tagwithnumber thenumber="1337"/> </innertag> − <innertag sampleattribute="innertagAttribute2"> <mytag>anddev.org rulez =)2</mytag> <tagwithnumber thenumber="13372"/> </innertag> </outertag>Parsed in 0.002 seconds, using GeSHi 1.0.8.4
I use this as my test xml, and want not only the last mytag and tagwithnumber to come up, what should I change in the example code to fix this?




Users browsing this forum: No registered users and 9 guests