ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have been assigned a project in software engineering a part of which is verifying the syntax of an xml file and then create a custom data model. A sample of this xml syntax is :
which means that in the c source file TestProgram.c there is a function named f1 which calls (uses) f2 and f3.
I currently try to work with DocumentBuilder like this:
which complains about "f1" being inside the "Function" tag. If I get this "f1" outside the tag, eg
Code:
<Function> f1
...
</Function>
it works ok. Is there a way to check the syntax and parse the file without changing xml source file using an already existing class? Or I have to write a new syntax verification/parser myself?
Is 'f1' literally that string? Because shouldn't it at least be named and its value quoted if an attribute? f1="f1"? Moving it to between the tags make it an element, no?
is not valid XML, and from my understanding of XML, that is correct. So, if you need to use the XML source as-is, then you cannot use a standard XML parser, and you will therefore have to write your own parser. It seems like a better idea to fix the (non-)XML source, and in so doing, gain the advantage of being able to use standard tools, and other benefits of XML.
This xml syntax was given to me in the specifications requirements (it is a project at software engineering class I'm attending), so I will ask the professor/"client" if we can change the specifications to use standard xml syntax, or I have to write my own parser. I just couldn't figure out if this syntax is wrong (which apparently is) or I was using the wrong parser. Thanks for the help.
For clarification, this is the error I get:
Code:
$ java eekp_test/imptest
Current wd is : /home/hitman/develop/sw_engineer/import
Enter filename : test.xml
Building object
Trying to parse file...
[Fatal Error] test.xml:4:17: Attribute name "f1" associated with an element type "Function" must be followed by the ' = ' character.
org.xml.sax.SAXParseException: Attribute name "f1" associated with an element type "Function" must be followed by the ' = ' character.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:249)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:208)
at eekp_test.importXml.verifySyntax(importXml.java:39)
at eekp_test.importXml.<init>(importXml.java:17)
at eekp_test.imptest.main(imptest.java:16)
Last edited by segmentation_fault; 01-04-2012 at 11:21 AM.
Ah there you have it. Yea, I never have personally seen an unassigned attribute like that, I don't think -- I guess that's because it isn't actually valid XML.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.