• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Parse with SAX and then store the data in String

 
Greenhorn
Posts: 9
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,

I parse the XMl file by using SAX parser ( my first attempt to use this) but I really do not know how I can store them as a String. I tried:



I use Java 8
Advance thanks.
 
Marshal
Posts: 64667
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you getting any output from any of your print statements?

I think this question is too difficult for this forum and shall move you to our XML forum.
 
Tony Kurt
Greenhorn
Posts: 9
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Are you getting any output from any of your print statements?


I think this question is too difficult for this forum and shall move you to our XML forum.



The code is working good and reads all the xml file sequentially but my next aim is compare this xml file (parsing into String) with another String and validate them by using Content Equality.
How can I transfer my question, could you please guide me?
 
Campbell Ritchie
Marshal
Posts: 64667
225
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have dealt with the forum transfer.

I hardly know any XML, so I can only make a few general suggestions.

Are you going to use equality of the text with String#equals or String#equalsIgnoreCase?
Are you going to create an object with fields based on the XML file and them compare them with their equals methods?
Are you going to put the Strings into Lists and them iterate the Lists comparing the Strings?
Are you going to put tag→value pairs into a Map and compare those Maps?
Are you going to use diff or similar to compare the two XML files?
 
Tony Kurt
Greenhorn
Posts: 9
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:I have dealt with the forum transfer.

I hardly know any XML, so I can only make a few general suggestions.

Are you going to use equality of the text with String#equals or String#equalsIgnoreCase?
Are you going to create an object with fields based on the XML file and them compare them with their equals methods?
Are you going to put the Strings into Lists and them iterate the Lists comparing the Strings?
Are you going to put tag→value pairs into a Map and compare those Maps?
Are you going to use diff or similar to compare the two XML files?



No equals() and equalsIgnoreCase()method are not beneficial in my situation. Since these two String include maybe same content but different order. For example String 1 which I parsed from XML includes name:tony age:23 and String 2 includes age:23 name:tony. Then the contents are the same.
 
Tony Kurt
Greenhorn
Posts: 9
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please help me... how can I store the data in String after Parsing XML file?
 
Ranch Hand
Posts: 624
9
BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then I think you have to parse the XML and store the data in collection of objects(POJO).
String is not going to work here.
 
Marshal
Posts: 6851
470
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouldn't work for you to create objects out of parsed xml files first? Name them appropriately and put in a suitable data structure. Then, compare them with implemented equals() method in the way you want.

You said equals() method is not beneficial in your situation. I'm tempted not to believe right away as you mentioned you want to compare them by their contents.
Could you show us such example xml files how they actually look like?
 
Tony Kurt
Greenhorn
Posts: 9
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tapas Chand wrote:Then I think you have to parse the XML and store the data in collection of objects(POJO).
String is not going to work here.



I will try this. Thank you
 
Saloon Keeper
Posts: 10308
217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you'll have to parse those Strings a second time to get an object that contains name and age as properties, and compare the two objects for equality.

I think the easiest way to do this is to use a Scanner and use one of the 'find' methods. Use word boundaries in your regular expression.
 
Tony Kurt
Greenhorn
Posts: 9
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tapas Chand wrote:Then I think you have to parse the XML and store the data in collection of objects(POJO).
String is not going to work here.



I use an online converter from XML to POJO Converter. But now I get 35 java class. Could you please help me how can I store the parsed XML. I think I could not understand you well
 
Tapas Chand
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tony Kurt wrote:I use an online converter from XML to POJO Converter. But now I get 35 java class. Could you please help me how can I store the parsed XML. I think I could not understand you well

You need to show your sample XML so that we can help you in the right direction.
 
Tony Kurt
Greenhorn
Posts: 9
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tapas Chand wrote:

Tony Kurt wrote:I use an online converter from XML to POJO Converter. But now I get 35 java class. Could you please help me how can I store the parsed XML. I think I could not understand you well

You need to show your sample XML so that we can help you in the right direction.



XSD Schema of my XML File

 
Tony Kurt
Greenhorn
Posts: 9
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tapas Chand wrote:

Tony Kurt wrote:I use an online converter from XML to POJO Converter. But now I get 35 java class. Could you please help me how can I store the parsed XML. I think I could not understand you well

You need to show your sample XML so that we can help you in the right direction.



Because of the privacy issue I could not share the xml file
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!