In android SDK, when I editing an android layout xml file, it can do validation and auto-complete. How does this work?
How can I make eclipse validate and auto-complete with my own defi开发者_运维问答ned xml format?
Eclipse can be used to edit and validate XML files. I use it quite often in my Eclipse for J2EE Developers.
First, you have to create preferably an XSD file to define the XML structure. Second, you have to create the XML file and define in it where the validator can find the XSD file.
The second point has more solutions. Either you specify the reference to the XSD file directly in the XML file (noNamespaceSchemaLocation
) or you specify only the namespace and system-id int the XML file and you set the actual path to the XSD file in the Eclipse IDE (Preferences->XML->XML Catalog, here you can map system-id to XSD URL).
Then just click the XML file with the right mouse button and select the Validate choice.
I think you need to have the Web Tools Platform (WTP) installed (via "Help -> Install New Software"). Once you have this installed, there should be an example project under "File -> New Project -> Examples -> XML -> Editing and validating XML files" which will help you get up to speed.
Move your layouts to a temp folder, then import again in layout folder.
This works because eclipse is aware of xsd-scheme and namespace used for the layout. You can look at the top of your document and see something like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
...
This xmlns
means xml-namespaces. It is defined by URI and contains all the options, you have available in current tag here. As for xml-structure xsd can be used. More of that on wiki.
this has nothing to do with the android API, the question is not relevant for the keywords you've posted. What you are looking for is eclipse plugin tutorial. eclipse has a build in support for xml, android's team built their own plugin to support android's xml, and i can tell you that it's only half working... in some custom events like custom 'attr' or your own classes it doesn't work.
In any case, if you want to write your own custom xml auto completer please check out eclipse doc site for eclipse plugins reference.
精彩评论