Parsing notepad content separated by pipes...urgent!!
Hi there,
I really need your help guys, I need to read the content of a notepad file and then parse it, specifically it's a string just like this one,
AAA_AAAA.01 | BBB_BBBB.01 BBB_BBBB.02 | BBB_BBBB.03 | CCC_CCCC.01 | DDD_DDDD.01 | DDD_DDDD.02 | DDD_DDDD.03 | DDD_DDDD.04....and so on,
and so far I've got only this code
package tokenizer;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
* @author Henz
public class ThreadParser {
public ThreadParser() {
// Auto-generated constructor stub
* @param args
public static void main(String[] args) {
// Auto-generated method stub
String line;
try {
System.out.print("Enter the path: ");
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
String file = stdin.readLine();
BufferedReader sfile = new BufferedReader(new FileReader(file));
File myFile = new File(file);
if (myFile.exists()) {
System.out.println("File founded, preparing parsing...");
} else {
System.out.println("File not founded, verify path...");
while ((( line = sfile.readLine())!= null))
System.out.println(line);
StringTokenizer st = new StringTokenizer(line)//Exactly here I need the string so I can parse it but it returns me a NullPointerEx
while(st.hasMoreTokens())
System.out.println(st.nextToken());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
But I've got only this output
Enter the path: C:\Test.txt
File founded, preparing parsing...
Exception in thread "main" java.lang.NullPointerException
at java.util.StringTokenizer.<init>(StringTokenizer.java.182)
at java.util.StringTokenizer.<init>(StringTokenizer.java.219)
at tokenizer.ThreadParser.main(ThreadParser.java:54)
The question is, what else do I need so I can get this output ,
AAA_AAAA.01
BBB_BBBB.01 BBB_BBBB.02 BBB_BBBB.03
CCC_CCCC.01
DDD_DDDD.01 DDD_DDDD.02 DDD_DDDD.03 DDD_DDDD.04
The main objective is to parse the string above eliminating its pipes and in each line having just the same type prefix words
Regards!
I will post the bad part of your code, indented correctly:while ((( line = sfile.readLine())!= null))
System.out.println(line);
StringTokenizer st = new StringTokenizer(line);The first two lines read through the file and copy it to standard output. After they are finished, the "line" variable is null (that's what the "while" does) and then you proceed to try and use it in the third line of code.
In other words, you should surround the code that you want controlled by that "while" by braces. Like this:while ((( line = sfile.readLine())!= null)) {
System.out.println(line);
StringTokenizer st = new StringTokenizer(line);
... and so on
}If you don't do that then only the single line of code after the "while" statement is in the while-loop.
Similar Messages
-
In excel I used the command "text to columns" to parse the contents of a single cell. The result would be to have the cell contents stretched across a series of cells. The separation was user defined based on common delimiters eg. comma, tab, space, etc. Can this function be performed in Numbers?
Hello
Welcome to the club.
I didn't met this kind of function when I looked at the 168 functions available in Numbers.
Some of them have a range of cells as operand but all of them apply to a single cell.
*Go to "Provide Numbers Feedback" in the "Numbers" menu*, describe what you wish.
Then, cross your fingers, and wait at least for iWork'09
Yvan KOENIG (from FRANCE vendredi 11 janvier 2008 20:50:30) -
Does JMS parse xml content in TextMessages
Hi
I am working on WLS 6.1sp2 and I am using jms TextMessage type of message to
send XML messages from one subsystem to another. I have added an XML registry
for my version of XML parser. Now I do not have any entries for the entity declarations
nor for the parser entries in the registry.
When I send in an XML message in a TextMessage envelope I find the following
errors in the log.
<Jun 9, 2003 3:56:57 PM PDT> <Error> <XML> <Failed to parse given XML document.
Failed to retrieve PUBLIC id. The root element is required in a well-formed docu
ment.>
<Jun 9, 2003 3:56:57 PM PDT> <Error> <XML> <Failed to open XML document. Failed
to retrieve PUBLIC id or SYSTEM id from the document. Decrease the number of cha
r between the beginning of the document and its root element.>
<Jun 9, 2003 3:56:57 PM PDT> <Error> <XML> <Failed to parse given XML document.
Failed to retrieve SYSTEM id. The root element is required in a well-formed docu
ment.>
<Jun 9, 2003 3:56:57 PM PDT> <Error> <XML> <Failed to open XML document. Failed
to retrieve PUBLIC id or SYSTEM id from the document. Decrease the number of cha
r between the beginning of the document and its root element.>
<Jun 9, 2003 3:56:57 PM PDT> <Error> <XML> <Failed to parse given XML document.
Failed to retrieve root tag. The root element is required in a well-formed docum
ent.>
<Jun 9, 2003 3:56:57 PM PDT> <Error> <XML> <Could not instantiate factory class
specified in the Server console. Invalid parameters: at least one of publicId,
s
ystemId, rootTag must be non-null>
[ChangeAwareClassLoader] : Name is : META-INF/services/org.apache.xerces.xni.par
ser.XMLParserConfiguration
<Jun 9, 2003 3:56:57 PM PDT> <Error> <XML> <Failed to open XML document. Failed
to retrieve PUBLIC id or SYSTEM id from the document. Decrease the number of cha
r between the beginning of the document and its root element.>
<Jun 9, 2003 3:56:57 PM PDT> <Error> <XML> <Failed to parse given XML document.
Failed to retrieve PUBLIC id. The root element is required in a well-formed docu
ment.>
Now from the logs I understand that the message is being parsed and since the
parser does not find any PUBLIC ID or SYSTEM id it dumps the error, since I am
using schemas there is none of the PUBLIC and SYSTEM ids in my xml, also this
is not logged by any component of my subsystems, this is a weblogic XML Service
log and when I trace through the code I find that it comes up after the first
subsystem sends the message and before the second subsystem receives it.
The question then is does JMS parse XML content in TextMessages and if so how
can I disable that parsing?
Thanks
Sandeep
JMS does not automatically parse TextMessages. Check the XML declaration in
your application's deployment descriptors. That's often the source of this
error.
FYI, you can use XMLMessage for xml payloads. As far as I can remember, the
XMLMessage is an extension of the TextMessage with xml parsing built in.
Adarsh
"Sandeep Nayak" <[email protected]> wrote in message
news:[email protected]...
>
> Hi
>
> I am working on WLS 6.1sp2 and I am using jms TextMessage type of message
to
> send XML messages from one subsystem to another. I have added an XML
registry
> for my version of XML parser. Now I do not have any entries for the entity
declarations
> nor for the parser entries in the registry.
>
> When I send in an XML message in a TextMessage envelope I find the
following
> errors in the log.
>
> <Jun 9, 2003 3:56:57 PM PDT> <Error> <XML> <Failed to parse given XML
document.
> Failed to retrieve PUBLIC id. The root element is required in a
well-formed docu
> ment.>
> <Jun 9, 2003 3:56:57 PM PDT> <Error> <XML> <Failed to open XML document.
Failed
> to retrieve PUBLIC id or SYSTEM id from the document. Decrease the number
of cha
> r between the beginning of the document and its root element.>
> <Jun 9, 2003 3:56:57 PM PDT> <Error> <XML> <Failed to parse given XML
document.
> Failed to retrieve SYSTEM id. The root element is required in a
well-formed docu
> ment.>
> <Jun 9, 2003 3:56:57 PM PDT> <Error> <XML> <Failed to open XML document.
Failed
> to retrieve PUBLIC id or SYSTEM id from the document. Decrease the number
of cha
> r between the beginning of the document and its root element.>
> <Jun 9, 2003 3:56:57 PM PDT> <Error> <XML> <Failed to parse given XML
document.
> Failed to retrieve root tag. The root element is required in a well-formed
docum
> ent.>
> <Jun 9, 2003 3:56:57 PM PDT> <Error> <XML> <Could not instantiate factory
class
> specified in the Server console. Invalid parameters: at least one of
publicId,
> s
> ystemId, rootTag must be non-null>
> [ChangeAwareClassLoader] : Name is :
META-INF/services/org.apache.xerces.xni.par
> ser.XMLParserConfiguration
> <Jun 9, 2003 3:56:57 PM PDT> <Error> <XML> <Failed to open XML document.
Failed
> to retrieve PUBLIC id or SYSTEM id from the document. Decrease the number
of cha
> r between the beginning of the document and its root element.>
> <Jun 9, 2003 3:56:57 PM PDT> <Error> <XML> <Failed to parse given XML
document.
> Failed to retrieve PUBLIC id. The root element is required in a
well-formed docu
> ment.>
>
> Now from the logs I understand that the message is being parsed and since
the
> parser does not find any PUBLIC ID or SYSTEM id it dumps the error, since
I am
> using schemas there is none of the PUBLIC and SYSTEM ids in my xml, also
this
> is not logged by any component of my subsystems, this is a weblogic XML
Service
> log and when I trace through the code I find that it comes up after the
first
> subsystem sends the message and before the second subsystem receives it.
>
> The question then is does JMS parse XML content in TextMessages and if so
how
> can I disable that parsing?
>
> Thanks
>
> Sandeep
-
Text file contains data separated by pipe symbol read the data and saved in
Hi ,
This is Sreedhar, i am new to java. my query is Report its in text file format it contains data like GLNO,name ,amount. All fields are separated by pipe(|) symbol. I would like to read that
data and saved into the database. Please anyone can help me.thx Ottobonn.
Scanner is very usefull with string operation like in my problem..but i want try to find java.util.Scanner in j2me, i can't found this class...:(
so, may be i can't use this class in j2me...
i new in java, so i try myself to code the simple method for my problem,
may be anyone can make this class more simple than my coding....:)
public StringPipe(String _msg){
String message = _msg;
int pipe = 0;
int lengthmessage = message.length();
int lengthMsgresult = 0;
while(lengthMsgresult<=lengthmessage){
String msg = null;
int pipeX = message.indexOf("|");
if(pipeX==-1){
msg = message;
else{
msg = message.substring(pipe, pipeX);
message = message.substring(pipeX+1, message.length());
lengthMsgresult += msg.length();
// the string seperated by pipe
System.out.println("msg = " + msg);
if(pipeX==-1){
break;
}thx... -
File content conversion for Pipe delimited file
Hi
i have a scenario ( file-xi-proxy) in whch file is coming in a pipe delimited.
my data type is like
DT_ XXXXX
AwardInfo
Header contains some fileds
DetailRecord contains some fileds
trailer contains some fields
what are content conversion parameters i have to use
venkatSedamkar,
Expecting you have one header, multiple details and one trailer then give recordset structure in sender file communication channel as:
Header,1,DetailRecord ,*,trailer,1
In content conversion you should give parameters:
Header.fieldSeparator : |
Header.endSeparator : 'nl'
DetailRecord.fieldSeparator : |
DetailRecord.endSeparator : 'nl'
trailer.fieldSeparator : |
trailer.endSeparator : 'nl'
You may need to change the parameters also according to your strcuture and the file layout. See this SAP help for file content conversion:
http://help.sap.com/saphelp_nw04/helpdata/en/e3/94007075cae04f930cc4c034e411e1/content.htm
http://help.sap.com/saphelp_nw04/helpdata/en/2c/181077dd7d6b4ea6a8029b20bf7e55/content.htm
Regards,
---Satish -
Problem with manage/consume content separation approach
Hi,
In the Portal 10G manual and in several other sources, ORACLE recommends separating content-management from content-publication in different page groups. That's the approach we've adopted, and it seems reasonable. BUT now I find that contents published as portlets are like black boxes not searchable in the page group where they are published! That and not giving search feature at all to the users is almost the same! There must be some solution for this, I find it a major drawback difficult to ignore, since it makes this approach unacceptable.
Please, any help on this will be very appreciated, for it may yield critical decisions in our portal development approach.
Big thanks in advance.The default portal search is a respository-based search, so will always return the page on which the item is managed. In your use case, it probably makes sense to either (1) not expose the page attribute in your search result (2) use UltraSearch as your end user facing search. Note that UltraSearch creates its index via a crawler, therefore will only return content that is 'public'.
If you have additional, follow-up questions on search options, I recommend a post on the portal search forum: http://forums.oracle.com/forums/forum.jsp?forum=12 -
XML Parser and Content-type/encoding problem
I've write a little and simple XML parser and a simple "trasformer" that recive an XML file and an XSL one and return HTML, here is the code:
public static String toHTML(Document doc, String xslSource){
ByteArrayOutputStream testo = new ByteArrayOutputStream();
try{
DOMSource source = new DOMSource(doc);
TransformerFactory tFactory = TransformerFactory.newInstance();
System.out.println("----> " + xslSource);
Transformer transformer = tFactory.newTransformer(new StreamSource(xslSource));
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.setOutputProperty(OutputKeys.METHOD, "html");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.transform(source, new StreamResult(testo));
}catch(Exception ioe){
System.out.println("2 XMLTool.toHTML " + new java.util.Date());
System.out.println(ioe);
return testo.toString();
}the problem is that I would like to put the HTML code its return into a JEditorPane; now I'm trying with this code:
JEditorPane jep1 = new JEditorPane();
jep1.setContentType("text/html");
jep1.setText(v);
// 'v' is the string returned by the code posted up (the XML/XSL transformer)but I can't see anything in my JEditorPane.
I think that the problem is this line of code that the transformer add automaticaly ad HTML code:
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">Infact if I try to delete this line from the code I can see what I want but is'n good delete a line of code without understend where is the problem.
So, can anyone help me?good.
when u set ur output properties to html , transformer
searches for all entity references and converts accordingly.
if u r using xalan these files will be used for conversion of
Character entity references for markup-significant
output_html.properties
(this should be in templates package)
and HTMLEntities.res(should be in serialize package)
vasanth-ct -
XML Parsing Base64 Content - Special Characters Umlaut etc
Hello!
I am currently parsing an XML file which has it's content encoded in Base64. My application parses the XML file (from a provider) and pass on the content to a GUI where the user can change the value of the nodes and store the same back in a new XML (which is then to be sent back to the provider). The Application uses only "UTF-8" . I am currently using the Base64 class provided at http://iharder.net/base64
The problem I have is that the special characters like �, � etc, are being depicted as (?) i.e. unreadable. Only when I control the decoding process i.e. String resoolt = new String (result.getBytes(), "UTF-8") do I get the correct content, and the same can be posted on the GUI.
The application produces an XML file (The application in question is a translation app), which when re-opened in the application for retranslation has the same problem... it is shown with teh special characters with (?).
After a lot of debugging I found that the XML produced by the application does not need the forcing of content into UTF-8 using the code above, it is read automatically correctly (with all the content correct), but due to the coding I have done... String resoolt = new String (result.getBytes(), "UTF-8") the nodes are decoded with the earlier problem umlauts et al missing.
Now I could use a test to differntiate between the two cases XML from the provider or the XML which is produced by my own app, and doesn"t work on the Provider and treat them differently, but I don't want this solution since the XML which my app produces is not accepted as input at the providers.
So my query.. what is the best way to go about it now... I am quite stymied >(
Thanks!
TimAmazingly enough some other user has the identical problem to yours and has expressed it in exactly the same words. Has the same name as you too.
http://forum.java.sun.com/thread.jspa?threadID=606929&tstart=0
(Cross-posting is frowned on here.) -
XI XML Parser: tag content with "'", single apostrophe: invalid character
Hi all,
we import XML-documents with the file adapter in a sender channel. everything works well.
But if one of the XML-tag contents contains a single apostrophe ( ' ), then the XML parser stops with an error "An invalid character was found inside an entity reference. ". The message can not be processed. If I test the message content in the mapping -> no error.
When the single apostrophe is dereferenced by an additional single apostrophe the XML-File can be processed.
Question: does anybody know how this can be handled because it is not very nice of SAP XI to send single apostrophes in outgoing messages but cannot handle it in incoming messages from other systems? special adapter settings?
Thank you very much
regards
Hanscheck bhavesh reply
Suppress Special Character
also check
https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/9420 [original link is broken] [original link is broken] [original link is broken]
Implementing a Java Mapping in SAP PI to remove Escape Sequences from a file -
Does Oracle XML Parser support Content Validation
Hi there,
Could someone out there give me a hint on whether the Oracle XML Parser has the capability of handling Content Validation? If yes, what's the mechanism behind it?
From my understanding of the Oracle XML Parser, even with the validating mode turned on, the parser only validates the XML data against the DTD (if any), which involves checking whether or not the attribute names and element tags are legal, whether nested elements belong to where they are, and so on. But I dont see any Content Validation. And my guess is that this feature, namely Content Validation, is simply not supported in the current version of the Oracle XML Parser. Am I right?
Any suggestion would be greatly appreciated. Thanks.
---Denali
nullHi there,
Could someone out there give me a hint on whether the Oracle XML Parser has the capability of handling Content Validation? If yes, what's the mechanism behind it?
From my understanding of the Oracle XML Parser, even with the validating mode turned on, the parser only validates the XML data against the DTD (if any), which involves checking whether or not the attribute names and element tags are legal, whether nested elements belong to where they are, and so on. But I dont see any Content Validation. And my guess is that this feature, namely Content Validation, is simply not supported in the current version of the Oracle XML Parser. Am I right?
Any suggestion would be greatly appreciated. Thanks.
---Denali
null -
How to parse XML content in JMS Message...
Hi everybody,
I am currently developing a Message-Driven Bean and has some problem parsing the XML data that contains in the JMS body.
The XML data is contained in TextMessage (JMS message type) and in order to parse the data, I need to use the DOM builder, which is expecting to read from a file (e.g. abc.xml).
My question is how can I use TextMessage (can be output to a String) as the input source instead of a file.
Thanks in advance.Hi Boon,
"Boon Keong" <[email protected]> wrote in message
news:3dd46800$[email protected]..
I am currently developing a Message-Driven Bean and has some problemparsing the XML data that contains in the JMS body.
>
The XML data is contained in TextMessage (JMS message type) and in orderto parse the data, I need to use the DOM builder, which is expecting to read
from a file (e.g. abc.xml).
>
My question is how can I use TextMessage (can be output to a String) asthe input source instead of a file.
What about this:
DocumentBuilder db = ...
Document doc = db.parse(new InputSource(new
StringReader(textMessage.toString()));
or
Document doc = db.parse(new
ByteArrayInputStream(textMessage.toString().getBytes()));
Regards,
Slava Imeshev -
Question in using sockets in parsing XML!!!!(urgent plz help)
i have a server/client program and the client has some XML files the server want to process and parse them using DOM.
But i want to do this without having to transfer neither the whole file nor line-by-line of the file
does anybody know how to do this???
how to connect the output stream of the socket of the client with this file??
thanks in advancei did it and here are the exact line of code to do it:
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
/factory.setValidating( true );
// obtain object that builds Documents
DocumentBuilder builder = factory.newDocumentBuilder();
URL url = new URL("file://comp1/xml/Stack.xml");
// obtain document object from XML document Document document = builder.parse( url.openConnection() .getInputStream() ); -
Alternatives to content area pages? URGENT!!
Hi...
I am implementing a site in Portal with a static navbar on the
left side with links to folders... this navbar will remain
static, the content that changes is in the rigth side..
If I make a new page from scratch, including the navbar and the
content area as portlets, when I click on a link on the left,
the page banner and the other portlets disappear, and appears
the content area page..... I read that the only way you can keep
that page appearance is to customize the content area page
itself.
Are there any other ways to do this? (not depending of the
content area page??)
Please, I need help ASAP!!Not in the current release. The next release of Portal, planned
for early 2002, will make this a lot easier.
Regards,
Jerry -
View BLOB content through Forms 6i URGENT... URGENT...
I have a table which stores word documents as BLOB. My database is on UNIX machine and I access the database through a Citrix machine through Oracle Forms. My client wishes to open the word document in Forms which is stored in BLOB in the database. My database version is 9.2 which supports me to import and export files from file system to BLOB and vice versa using DBMS_BLOB and UTL_FILE packages. But, my only concern is regarding opening the word document through Forms 6i. Is that possible through OLE or any other means? I've tried all the sources. I know I can do it using Webutil, but it will not work for Forms 6i. Please help me in this regard. I have an urgent release tonight. Please. Please. Please. Please help me. Thanks in advance.
I know that OLE can solve the problem. But issues is my word document is stored as BLOB in the database. My database is in UNIX. So, I can't export my files into UNIX and open them. I can't view them either from Forms. Please let me know if you have any alternative. Please can you guide me with step by step procedure as to how this can be done if we can do it using OLE.
-
Content Expiry notification (Very urgent)
Hi,
Is there any way to configure Expired content should be notified to the appropriate content creator prior to the date and again prompted on date of expiry via UWL and Email.
Thanks and Regards,
Jack.Hi Jack,
I'm affraid this works as designed.
If you active both services as mentioned by Patricio you will get a "Created" notification if a document is first published based on its "Valid From" field but there is no such notification for "Expired" documents.
Without implementation I'm affraid you can only make use of the <a href="http://help.sap.com/saphelp_nw04/helpdata/en/42/373042d1401a2ae10000000a1550b0/content.htm">Report for Time-Based Publishing</a> but this does not create notifications.
Regards,
Robert
Maybe you are looking for
-
Using Spry / radio button on CFFORM??
Has anyone done something like this? I'm trying to find instructions on how to have a form that I can have users select 1 of 2 (or more) options. Based on the option they pick, I'd like the Spry accordion widget to display the appropirate form option
-
Adding "room tone" before or after a slide's existing audio
As a result of my experience in video production, the steps I use to create my Captivate 3 software application demos are: (1) rehearsing my software application scenarios in advance (2) scripting my voice-over narration tightly (3) recording my narr
-
Location Services not working after iOS6 update
After updating to iOS 6 my ipad (3), Location Services no longer work, siri doesn't know where I am, 'Find My iPhone'cannot locate any devices, Maps cant find my position...and so on. I have double checked all seetings and they are correct. There was
-
How to shuffle photos when creating a slideshow?
When I click the slideshow button on an album I have the option to shuffle photos, but do not have the same option when I create a slideshow. I want to save the slideshow; can I save a slideshow played after using the slideshow button? Or how can I s
-
I am using CC and I want to export my indesign project to a fixed layout epub. When I go to export I am only given the option to export to a regular epub and not a fixed layout epub. How will I be able to export this as a fixed layout?