CN104537084A - Method for locating XML text - Google Patents
Method for locating XML text Download PDFInfo
- Publication number
- CN104537084A CN104537084A CN201410855376.0A CN201410855376A CN104537084A CN 104537084 A CN104537084 A CN 104537084A CN 201410855376 A CN201410855376 A CN 201410855376A CN 104537084 A CN104537084 A CN 104537084A
- Authority
- CN
- China
- Prior art keywords
- text
- node
- xml
- node object
- play amount
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/80—Information retrieval; Database structures therefor; File system structures therefor of semi-structured data, e.g. markup language structured data such as SGML, XML or HTML
- G06F16/81—Indexing, e.g. XML tags; Data structures therefor; Storage structures
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F40/00—Handling natural language data
- G06F40/10—Text processing
- G06F40/12—Use of codes for handling textual entities
- G06F40/14—Tree-structured documents
Abstract
The invention discloses a method for locating an XML text. The method comprises the following steps that a text index and text offset of a node object are stored on the node object of a DOM; the text index is the initial position of the XML text of the node object in the whole XML text; the text offset is the difference value of the modified text length and an initial text length after the XML text of the node object is modified; when the node object in the DOM is selected, the text index of the node object and the text offset of all upper brother nodes and all father nodes of the node object and the upper brother nodes of all the father nodes are overlapped, and the position of the XML text corresponding to the node object is located. Text content comparison does not need to be carried out, and the position of the XML text corresponding to the node object of the DOM is fast located.
Description
Technical field
The present invention relates to a kind of XML String localization technology, particularly relate to a kind of XML String localization technology based on DOM model.
Background technology
DOM (DOM Document Object Model) is the proposed standard of W3C (World Wide Web Consortium).DOM defines access and processes the standard of such as XML and XHTML document.DOM (DOM Document Object Model) is the content making program and script have the ability dynamically to access and upgrade document, structure and a platform for pattern and the interface of language-neutral.
XML DOM defines object and the attribute of all XML elements, and accesses their method (interface).In other words, XML DOM is the standard for obtaining, changing, add or delete XML element.
The DOM model of XML document mainly achieves the mutual of data and interface, namely described by XML data, these data are shown as the mode of text or figure, and DOM model is as a kind of programmed method controlling these data.Due to the mapping relations that DOM model and XML data are corresponding, in application process, can first revise DOM model data, then derive corresponding XML data; Also after first can revising XML data, then DOM model is upgraded.As webpage design, can directly be operated by graphic interface, also can by the mode of operation of text, but which kind of mode that don't work is revised, and DOM model is same all the time.At present, general application software is reloaded text data, is regenerated corresponding DOM model after all adopting amendment XML text.Delete original DOM model, then analyzing XML file or internal storage data form DOM model again again, this mode may affect not quite for smaller XML file or internal storage data, but for large XML file or internal storage data, obvious efficiency is not high.
If wish when keeping the mapping relations of existing DOM model and XML data, realize the amendment of local XML text data, so that by amended local XML text fast mapping to DOM structure, adapt to the XML edit pattern of large files, then there is a new problem: how rapidly from the node mapping of DOM structure to XML text.
Summary of the invention
The technical matters that the present invention mainly solves is to provide a kind of XML text positioning method, makes it possible to the comparison without the need to carrying out content of text, the XML text position corresponding to quick position DOM model node object.
In order to solve the problems of the technologies described above, the invention provides a kind of XML text positioning method, comprising following steps:
The node object of DOM model is preserved text index and the text side-play amount of this node object; Text index is: the initial position of XML text in whole XML text of this node object; Text side-play amount is: after the XML text of this node object is modified, the difference of its amended text size and original text length;
When node object in DOM model is selected, by the superposition of the text side-play amount of the upper strata brotgher of node of the text index of this node object and this node object all upper stratas brotgher of node, all father nodes and all father nodes, locate the XML text position that this node object is corresponding.
As further improvement, the method can also comprise following steps:
The node object of DOM model is preserved the current content of text of this node object.
As further improvement, the method can also comprise following steps:
When the XML text that DOM model interior joint object is corresponding is modified, if amended text size is different from text size before amendment, then revise the text side-play amount of this node object according to both differences.
As further improvement, revise in the step of text side-play amount of this node object according to the difference of text size before and after amendment, if amended text size is less than the text size before amendment, then on current text offset basis, deduct this difference, if amended text size is greater than the text size before amendment, then on the basis of current text side-play amount, add this difference.
As further improvement, the method can also comprise following steps:
When DOM model interior joint object is deleted, the text side-play amount of the nearest upper layer node of this deleted node is modified, its text side-play amount is deducted the current text size of this deleted node and text side-play amount.
As further improvement, the method can also comprise following steps:
In DOM model during newly-increased node object, the text index of this newly-increased node is current text size, text side-play amount and the text index sum of its nearest upper layer node, and the text side-play amount of this node increased newly is its original text length.
As further improvement, the node object of DOM model is preserved in the step of the current content of text of this node object:
For leaf node, preserve all XML content of text that this node object is corresponding, for non-leaf nodes, preserve the first half XML content of text that this node object is corresponding.
As further improvement, above-mentioned text size comprises newline.
Compared with prior art, the key distinction and effect thereof are embodiment of the present invention: text index and the text side-play amount of on the node object of DOM model, preserving this node object; Text index is: the initial position of XML text in whole XML text of this node object; Text side-play amount is: after the XML text of this node object is modified, the difference of its amended text size and original text length; When node object in DOM model is selected, by the superposition of the text side-play amount of the upper strata brotgher of node of the text index of this node object and this node object all upper stratas brotgher of node, all father nodes and all father nodes, locate the XML text position that this node object is corresponding.Make it possible to the comparison without the need to carrying out content of text, XML text position corresponding to quick position DOM model node object, thus conveniently can realize the amendment of local XML text data, and make amended data can fast mapping to original DOM structure, the speed of XML text editing can be accelerated, can be applicable to the XML edit pattern of large files.
Accompanying drawing explanation
Fig. 1 is the process flow diagram of XML text positioning method in the present invention one better embodiment.
Fig. 2 is the illustraton of model preserving the content of text of this node object, text index and text side-play amount in the present invention one better embodiment on the node object of DOM model.
Embodiment
For making the object, technical solutions and advantages of the present invention clearly, below in conjunction with accompanying drawing, embodiments of the present invention are described in further detail.
The present invention one better embodiment relates to a kind of XML text positioning method, and its particular flow sheet as shown in Figure 1.
In step 101, the node object of DOM model is preserved the content of text of this node object, text index and text side-play amount; Text index is: the initial position of XML text in whole XML text of this node object; Text side-play amount is: after the XML text of this node object is modified, the difference of its amended text size and original text length.In present embodiment, the initial value of text side-play amount is 0.
In this step: for leaf node, original text length is the length of all XML texts that this node object is corresponding; For non-leaf nodes, original text length is the length of the first half XML text that this node object is corresponding.
In step 102, in DOM model, certain node object is selected.
In step 103, by the superposition of the text side-play amount of the upper strata brotgher of node of the text index of this node object and this node object all upper stratas brotgher of node, all father nodes and all father nodes, locate the XML text position that this node object is corresponding.
The process of searching the text side-play amount of the upper strata brotgher of node of all upper stratas brotgher of node, all father nodes and all father nodes is: the text side-play amount of first looking for oneself the upper strata brotgher of node, look for the text side-play amount of father node again, look for the text side-play amount of the upper strata brotgher of node of father node again, by that analogy, until root node.
In step 104, the XML text that this node object is corresponding is modified.
In step 105, whether the text size before judging amended XML text size and initially revising is identical, if amended text size is different from initially revising front text size, then enters step 106, the text side-play amount of this node object of amendment is set according to both differences.Specifically, if amended text size is less than the text size before initial amendment, then on current text offset basis, deduct this difference, if amended text size is greater than the text size before amendment, then on the basis of current text side-play amount, add this difference.Then text side-play amount is negative value, if amended text size is greater than original text length, then text side-play amount be on the occasion of.If amended text size is identical with original text length, then process ends is not to the text side-play amount of this node.
For example, current have XML text content as follows:
In above text fragments, " body ", " div ", " a ", " p " carry out record as DOM node object.Attribute " href ", " name " is had, nodal value " setting " inside " a " object.
In the present embodiment, on each node object, first preserve the original text length of this node object, text index and text side-play amount.For leaf node, original text length is the length of all XML texts that this node object is corresponding; For non-leaf nodes, original text length is the length of the first half XML text that this node object is corresponding.
Be specifically described for above-mentioned each node, as shown in Figure 2, its interior joint " a ", " p " are leaf node, and " body ", " div " are non-leaf nodes.The first half content of text that node object " body " is corresponding is <body>, text size is 7 (carriage returns containing end), the text index i.e. XML text initial position of this node object " body " is 0, and original text side-play amount is 0; The first half content of text that node object " div " is corresponding is <div id=" u " >, and text size is 13 (carriage returns containing end), and text index is 7, and original text side-play amount is 0; The full text content that node object " a " is corresponding is that <a href=" setting.html " name=" setting " > arranges </a>, text size is 47 (carriage returns containing end), text index is 20, and original text side-play amount is 0; The full text content that node object " p " is corresponding is <p id=" lg " src=" sylogo1.gif " width=" 270 " height=" 129 "/>, text size is 56 (carriage returns containing end), text index is 67, and original text side-play amount is 0.
When the XML text of each node object is not modified, can directly according to the text index of node object, the XML text that location text object is corresponding.
When the XML text of wherein a certain node object is modified, and amended text size is when changing, the side-play amount of this node object is revised according to the difference of the front text size of amended text size and amendment, suppose that node object " div " is modified, change <div id=" uuu " > into, then its side-play amount is+2.
When the XML text of node object is modified, the mode of locating XML text position corresponding to a certain node object is: by the superposition of the text side-play amount of the upper strata brotgher of node of the text index of this node object and this node object all upper stratas brotgher of node, all father nodes and all father nodes, locate the XML text position that this node object is corresponding.
Suppose that present node " a " is selected, then by superimposed for the side-play amount 0 of the side-play amount+2 of its text index 20 and its father node " div ", father node " body ", obtaining XML text position corresponding to this node object is 22.
In step 107, DOM model interior joint object is deleted.
In step 108, the text side-play amount of the nearest upper layer node of this deleted node (can be father node also can be the upper strata brotgher of node) is modified, its text side-play amount is deducted the current text size of this deleted node and text side-play amount.
In step 109, newly-increased node object in DOM model.
In step 110, preserve the content of text of this newly-increased node object, text index and text side-play amount.The text index of this newly-increased node is current text size, text side-play amount and the text index sum of its nearest upper layer node (can be father node also can be the upper strata brotgher of node), and the text side-play amount of this node increased newly is its original text length.
By the way, make it possible to without the need to comparing to the content of text of DOM node object, XML text position corresponding to quick position DOM model node object, thus conveniently can realize the amendment of local XML text data, and make amended data can fast mapping to original DOM structure, the speed of XML text editing can be accelerated, can be applicable to the XML edit pattern of large files.
Although by referring to some of the preferred embodiment of the invention, to invention has been diagram and describing, but those of ordinary skill in the art should be understood that and can do various change to it in the form and details, and without departing from the spirit and scope of the present invention.
Claims (8)
1. an XML text positioning method, is characterized in that, comprises following steps:
The node object of DOM model is preserved text index and the text side-play amount of this node object; Described text index is: the initial position of XML text in whole XML text of this node object; Described text side-play amount is: after the XML text of this node object is modified, the difference of its amended text size and original text length;
When node object in described DOM model is selected, by the superposition of the text side-play amount of the upper strata brotgher of node of the text index of this node object and this node object all upper stratas brotgher of node, all father nodes and all father nodes, locate the XML text position that this node object is corresponding.
2. XML text positioning method according to claim 1, is characterized in that, also comprise following steps:
The node object of DOM model is preserved the current content of text of this node object.
3. XML text positioning method according to claim 2, is characterized in that, also comprise following steps:
When the XML text that described DOM model interior joint object is corresponding is modified, if amended text size is different from text size before amendment, then revise the text side-play amount of this node object according to both differences.
4. XML text positioning method according to claim 3, it is characterized in that, the described difference according to amendment front and back text size is revised in the step of text side-play amount of this node object, if amended text size is less than the text size before amendment, then on current text offset basis, deduct this difference, if amended text size is greater than the text size before amendment, then on the basis of current text side-play amount, add this difference.
5. XML text positioning method according to claim 2, is characterized in that, also comprise following steps:
When described DOM model interior joint object is deleted, the text side-play amount of the nearest upper layer node of this deleted node is modified, its text side-play amount is deducted the current text size of this deleted node and text side-play amount.
6. XML text positioning method according to claim 2, is characterized in that, also comprise following steps:
In described DOM model during newly-increased node object, the text index of this newly-increased node is current text size, text side-play amount and the text index sum of its nearest upper layer node, and the text side-play amount of this node increased newly is its original text length.
7. XML text positioning method according to claim 2, is characterized in that, describedly preserves in the step of the current content of text of this node object on the node object of DOM model:
For leaf node, preserve all XML content of text that this node object is corresponding, for non-leaf nodes, preserve the first half XML content of text that this node object is corresponding.
8. XML text positioning method as claimed in any of claims 1 to 7, is characterized in that, described text size comprises newline.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410855376.0A CN104537084A (en) | 2013-12-31 | 2014-12-31 | Method for locating XML text |
Applications Claiming Priority (3)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN2013107540523 | 2013-12-31 | ||
CN201310754052 | 2013-12-31 | ||
CN201410855376.0A CN104537084A (en) | 2013-12-31 | 2014-12-31 | Method for locating XML text |
Publications (1)
Publication Number | Publication Date |
---|---|
CN104537084A true CN104537084A (en) | 2015-04-22 |
Family
ID=52852612
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201410855376.0A Pending CN104537084A (en) | 2013-12-31 | 2014-12-31 | Method for locating XML text |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN104537084A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107644054A (en) * | 2017-07-26 | 2018-01-30 | 北京海泰方圆科技股份有限公司 | Method for information display and device |
CN110633465A (en) * | 2019-07-19 | 2019-12-31 | 广州视源电子科技股份有限公司 | Text sequence modification positioning method and device and electronic equipment |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1790335A (en) * | 2005-12-19 | 2006-06-21 | 无锡永中科技有限公司 | XML file data access method |
US20090282349A1 (en) * | 2008-05-08 | 2009-11-12 | Dialogic Corporation | System and method for dynamic configuration of components of web interfaces |
CN101819596A (en) * | 2010-04-28 | 2010-09-01 | 烽火通信科技股份有限公司 | Memory-based XML script buffer |
CN101986311A (en) * | 2010-11-17 | 2011-03-16 | 浙江省电力试验研究院 | Method for buffering node elements when rapidly processing large-scale XML file |
CN101996252A (en) * | 2010-11-17 | 2011-03-30 | 浙江省电力试验研究院 | Expression method of indexing information for node element in XML (Extensive Makeup Language) file |
-
2014
- 2014-12-31 CN CN201410855376.0A patent/CN104537084A/en active Pending
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1790335A (en) * | 2005-12-19 | 2006-06-21 | 无锡永中科技有限公司 | XML file data access method |
US20090282349A1 (en) * | 2008-05-08 | 2009-11-12 | Dialogic Corporation | System and method for dynamic configuration of components of web interfaces |
CN101819596A (en) * | 2010-04-28 | 2010-09-01 | 烽火通信科技股份有限公司 | Memory-based XML script buffer |
CN101986311A (en) * | 2010-11-17 | 2011-03-16 | 浙江省电力试验研究院 | Method for buffering node elements when rapidly processing large-scale XML file |
CN101996252A (en) * | 2010-11-17 | 2011-03-30 | 浙江省电力试验研究院 | Expression method of indexing information for node element in XML (Extensive Makeup Language) file |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107644054A (en) * | 2017-07-26 | 2018-01-30 | 北京海泰方圆科技股份有限公司 | Method for information display and device |
CN107644054B (en) * | 2017-07-26 | 2019-02-19 | 北京海泰方圆科技股份有限公司 | Information display method and device |
CN110633465A (en) * | 2019-07-19 | 2019-12-31 | 广州视源电子科技股份有限公司 | Text sequence modification positioning method and device and electronic equipment |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CA2517409C (en) | Method, system, and computer-readable medium for creating and laying out a graphic within an application program | |
KR101961970B1 (en) | Dynamically updating a running page | |
US8166449B2 (en) | Live bidirectional synchronizing of a visual and a textual representation | |
KR101312867B1 (en) | Markup based extensibility for user interfaces | |
US7743325B2 (en) | Method and computer-readable medium for fitting text to shapes within a graphic | |
US20110258538A1 (en) | Capturing DOM Modifications Mediated by Decoupled Change Mechanism | |
CN108351768B (en) | Method for implementing a user interface for processing data of an information system while writing a document in a markup language | |
CN104699714B (en) | Book version formatted file is converted to the method and device of EPUB formatted files | |
CN108647025A (en) | Processing method and processing device, electronics and the storage device of DOM Document Object Model interior joint | |
CN103514147A (en) | Method and system for copying and pasting webpage content | |
US20100162095A1 (en) | Data processing apparatus and data processing method | |
US20100218083A1 (en) | Document processing apparatus and document processing method | |
WO2015057457A1 (en) | Systems and methods to segment text for layout and rendering | |
CN110347390A (en) | A kind of method quickly generating WEB page, storage medium, equipment and system | |
US9063949B2 (en) | Inferring a sequence of editing operations to facilitate merging versions of a shared document | |
CN104537084A (en) | Method for locating XML text | |
CN103914437A (en) | XML (X Exrensible Markup Language) text positioning method based on DOM (Document Object Model) model | |
CN104281604B (en) | Method and system for generating Target Link data dictionary hierarchical tree | |
WO2007052680A1 (en) | Document processing device and document processing method | |
CN104516971A (en) | Method for combining background pictures in CSS style file | |
US10482165B2 (en) | Declarative cascade reordering for styles | |
CN104834508A (en) | Method for generating codes used for reading and writing binary file | |
US10261980B2 (en) | Method and system for persisting add-in data in documents | |
CN114154092B (en) | Method for translating web pages and related product | |
CN110196965A (en) | The method and device of XML file conversion Word file |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
WD01 | Invention patent application deemed withdrawn after publication |
Application publication date: 20150422 |
|
WD01 | Invention patent application deemed withdrawn after publication |