HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Nougat 7.1
|
7.1.1_r28
下载
查看原文件
收藏
根目录
sdk
docs
Notes_on_WST_StructuredDocument.txt
Notes on WST StructuredDocument ------------------------------- Created: 2010/11/26 References: WST 3.1.x, Eclipse 3.5 Galileo To manipulate XML documents in refactorings, we sometimes use the WST/SEE "StructuredDocument" API. There isn't exactly a lot of documentation on this out there, so this is a short explanation of how it works, totally based on _empirical_ evidence. As such, it must be taken with a grain of salt. Examples of usage can be found in sdk/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/refactorings/ 1- Get a document instance -------------------------- To get a document from an existing IFile resource: IModelManager modelMan = StructuredModelManager.getModelManager(); IStructuredDocument sdoc = modelMan.createStructuredDocumentFor(file); Note that the IStructuredDocument and all the associated interfaces we'll use below are all located in org.eclipse.wst.sse.core.internal.provisional, meaning they _might_ change later. Also note that this parses the content of the file on disk, not of a buffer with pending unsaved modifications opened in an editor. There is a counterpart for non-existent resources: IModelManager.createNewStructuredDocumentFor(IFile) However our goal so far has been to _parse_ existing documents, find the place that we wanted to modify and then generate a TextFileChange for a refactoring operation. Consequently this document doesn't say anything about using this model to modify content directly. 2- Structured Document overview ------------------------------- The IStructuredDocument is organized in "regions", which are little pieces of text. The document contains a list of region collections, each one being a list of regions. Each region has a type, as well as text. Since we use this to parse XML, let's look at this XML example: \n
\n
Some Value
\n
This will result in the following regions and sub-regions: (all the constants below are located in DOMRegionContext) XML_PI_OPEN XML_PI_OPEN: XML_TAG_NAME:xml XML_TAG_ATTRIBUTE_NAME:version XML_TAG_ATTRIBUTE_EQUALS:= XML_TAG_ATTRIBUTE_VALUE:"1.0" XML_TAG_ATTRIBUTE_NAME:encoding XML_TAG_ATTRIBUTE_EQUALS:= XML_TAG_ATTRIBUTE_VALUE:"utf-8" XML_PI_CLOSE:?> XML_CONTENT XML_CONTENT:\n XML_TAG_NAME XML_TAG_OPEN:< XML_TAG_NAME:resources XML_TAG_CLOSE:> XML_CONTENT XML_CONTENT:\n + whitespace before color XML_TAG_NAME XML_TAG_OPEN:< XML_TAG_NAME:color XML_EMPTY_TAG_CLOSE:/> XML_CONTENT XML_CONTENT:\n + whitespace before string XML_TAG_NAME XML_TAG_OPEN:< XML_TAG_NAME:string XML_TAG_ATTRIBUTE_NAME:name XML_TAG_ATTRIBUTE_EQUALS:= XML_TAG_ATTRIBUTE_VALUE:"my_string" XML_TAG_CLOSE:> XML_CONTENT XML_CONTENT:Some Value XML_TAG_NAME XML_END_TAG_OPEN: XML_TAG_NAME:string XML_TAG_CLOSE:> XML_CONTENT XML_CONTENT: (2 spaces before the comment) XML_COMMENT_TEXT XML_COMMENT_OPEN:
登录后可以享受更多权益
您还没有登录,登录后您可以:
收藏Android系统代码
收藏喜欢的文章
多个平台共享账号
去登录
首次使用?从这里
注册