0

I have a XML parser (finished) could deal with a subset of XML files. However, currently I have a XML file could not directly process by my parser.

There are two options to me:

1). I have to add more code on my parser;

2). maybe I can do some pre-processing before I feed the XML file into my parser;

My Question is:

Is there any way to modify XML file (delect tags and create entities)?

BTW: the output of pre-processing should be also XML file.

4
  • Is the XML file well-formed? Or is your parser lacking a particular feature? Commented Dec 27, 2013 at 11:37
  • 1
    Are you aware of DOM, SAX, StAX interfaces? Why wouldn't you use industry standard XML parsers and tools, like Xerces or JDOM2? In which aspects your parser is better than these tools? You probably should download source code of some XML parser and learn it a little bit. Commented Dec 27, 2013 at 11:39
  • 1
    never reinvent the wheel, unless you need to learn how to build your own wheels. If you primary goal is to learn, then sure, add code to your parser. If you want to get something done, and parsing is only a small part of it, use any of the tools suggested by @akhikhl Commented Dec 27, 2013 at 12:25
  • actually, current work is based on XStream, and I don't want to support all kinds of XML files. That's why I want to do a pre-processing work instead of extend the current parser. I think it will be more straight-forward. Commented Dec 27, 2013 at 12:57

1 Answer 1

1

In fairness, unless you're willing to repeatedly extend your XML parser or your preprocesser, there will always be XML files that your current parser can't handle.

So it worth considering whether that's a good approach or whether it's worth switching to an existing XML parser. The benefits of that is that you don't need to extend the parser or write a preprocessor, it's then a matter of utilizing the features of that XML parser.

If you're writing this XML parser for learning purposes then it's worth extending the parser itself. It really depends on the feature that you'd need to implement but it doesn't seem right to have parser that lacks functionality and then to remedy that with a preprocessor.

Of course, there may be situations where it's faster or more effective to use a preprocessor instead but your question currently doesn't include enough information to decide on that.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi Simeon. Actually my work is based on XStream. actually my initial problem is posted here: stackoverflow.com/questions/20798905/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.