aspose file tools*
The moose likes XML and Related Technologies and the fly likes DOM Parser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "DOM Parser" Watch "DOM Parser" New topic
Author

DOM Parser

Je Th
Greenhorn

Joined: Dec 03, 2003
Posts: 12
Evry Example I have tried to validate a xml file to a dtd are based on that the user want to parse a file. What if i want to parse and xmldocument from that hasnt been written to the hd yet? I have methods for create a DOM-object and a method for writing it to a file. Im trying to use this code from the faq to parse my to-be-xml-file but i cant get it to work could anyone help me or point me to the right direction.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the XML forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
parser.parse("data.xml"); // <--- Here i want to parse a doc, not file
Could you elaborate on this (if "doc" means org.w3c.dom.Document, it is already parsed...)?
For example, do you want to do
- parse("<?xml version='1.0'?><root><foo/><bar>...</bar></root>");
- parse(java.io.InputStream)
- something else?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Je Th
Greenhorn

Joined: Dec 03, 2003
Posts: 12
I want the source to be non-physic-file. I tried do type, parser.parse(MyDocument) where myDocument is the result of The scenario is that i want to validate a xmldoc to a DTD before i write it down in a file. Accrding to my resources the parse-method only accepts, File, URL resource, InpuStream & String data. So here is the deal really basic.
1. Load xml-flie from hd
2. Add more info to it
3. Validate old info + new info with a dtd
4. If sucessfull then write it down to a file on the hd.
Im done with all taks accept number 3. Validating the new document against a DTD.
Thanks for your time..
[ February 18, 2004: Message edited by: Je Th ]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
You could combine this and this to produce an in-memory XML file including a DOCTYPE declaration, and then parse it like this.
It's a bit ugly, but should work.
 
Consider Paul's rocket mass heater.
 
subject: DOM Parser