CN108959095B - Method for verifying XML document based on XML Schema - Google Patents

Method for verifying XML document based on XML Schema Download PDF

Info

Publication number
CN108959095B
CN108959095B CN201810762652.7A CN201810762652A CN108959095B CN 108959095 B CN108959095 B CN 108959095B CN 201810762652 A CN201810762652 A CN 201810762652A CN 108959095 B CN108959095 B CN 108959095B
Authority
CN
China
Prior art keywords
error
document
node
type
xml
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.)
Active
Application number
CN201810762652.7A
Other languages
Chinese (zh)
Other versions
CN108959095A (en
Inventor
吴家菊
纪斌
刘振吉
杨永辉
陈泉根
程铮
颜运强
蒙立荣
马永起
李龚亮
秦英
彭婉怡
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
COMPUTER APPLICATION RESEARCH INST CHINA ACADEMY OF ENGINEERING PHYSICS
Original Assignee
COMPUTER APPLICATION RESEARCH INST CHINA ACADEMY OF ENGINEERING PHYSICS
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by COMPUTER APPLICATION RESEARCH INST CHINA ACADEMY OF ENGINEERING PHYSICS filed Critical COMPUTER APPLICATION RESEARCH INST CHINA ACADEMY OF ENGINEERING PHYSICS
Priority to CN201810762652.7A priority Critical patent/CN108959095B/en
Publication of CN108959095A publication Critical patent/CN108959095A/en
Application granted granted Critical
Publication of CN108959095B publication Critical patent/CN108959095B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/366Software debugging using diagnostics
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/0703Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation
    • G06F11/079Root cause analysis, i.e. error or fault diagnosis

Abstract

The invention discloses a method for verifying an XML document based on an XML Schema, which comprises the following steps: s1, realizing a DOM (document object model) programming interface by using the Java language, and analyzing the XML document to obtain a corresponding analyzed document DOMdoc; s2, carrying out integrity check on the DOMdoc of the analysis document to judge whether a grammar error exists; s3, outputting error information; s4, defining an error location tracking function. The invention provides a method for verifying an XML document based on an XML Schema, which can verify the grammar correctness of the XML document based on the XML Schema, supports error information output and error information tracking in specific application, and is convenient for data editors to know error reasons and quickly find grammar error positions so as to accurately and quickly modify grammatical errors.

Description

Method for verifying XML document based on XML Schema
Technical Field
The invention relates to a method for use in software design situations. More particularly, the present invention relates to a method for validating XML based on XML Schema in the context of software design.
Background
Xml (extensible Markup language) is a common format for data description and exchange, and has been widely used on the Internet and inside enterprises. Due to the universality and interchangeability of XML, XML is widely used to describe comprehensive security data in the field of comprehensive security of weaponry. Before the edited XML document is applied to a comprehensive guarantee system or other application fields, the grammar correctness verification is required to be carried out on the edited XML document according to the design document of the XML document. The correct XML document can be verified to be applied to the related art.
The XML Schema is the standard recommended by W3C Recommendation and is the basis of XML application. The XML Schema may be used to design, constrain, and validate XML documents. The XML Schema document explicitly defines the application rules of the elements in the XML document, such as the names of the elements, the attributes that the elements have, the appearance order, the appearance times, the data types, the parent elements, the child elements, and so on. Therefore, the edited XML document can meet the design requirement of the XML document only after being verified to be correct by the XML Schema document, and the XML document can be applied to a weapon and equipment comprehensive guarantee system or other application fields.
However, the existing patent technology can only verify the correctness of the XML document based on the XML Schema, output specific error information is fuzzy, and syntax error tracking in practical application is not supported, so that defects exist in application, and further design, expansion and optimization are not facilitated.
Disclosure of Invention
An object of the present invention is to solve at least the above problems and/or disadvantages and to provide at least the advantages described hereinafter.
It is still another object of the present invention to provide a method for validating an XML document based on XML Schema, which can validate the correctness of the syntax of the XML document based on XML Schema, and support error information output and error information tracking in specific applications, so as to facilitate data editors to know the error reason and quickly find the syntax error position, so as to make accurate and quick modification for syntax errors.
To achieve these objects and other advantages and in accordance with the purpose of the invention, there is provided a method for validating an XML document based on an XML Schema, comprising:
s1, realizing a DOM (document object model) programming interface by using the Java language, and analyzing the XML document to obtain a corresponding analyzed document DOMdoc;
s2, carrying out integrity check on the DOMdoc of the analysis document to judge whether a grammar error exists;
s3, outputting error information;
s4, defining an error position tracking function;
the tracking function determines error information according to the mouse clicking position, finds a node corresponding to the error information in the DOMdoc, and displays the node in a mode different from other nodes, wherein the specific implementation mode depends on the display mode of the DOMdoc document.
Preferably, in S1, an Error class Error and related variables are defined;
wherein the definition of the relevant variables comprises:
a String type variable content for storing error information, an initial value of which is configured as an empty String;
another variable Error for holding ArrayList < Error > type created for syntax errors present in XML document;
the establishment of the Error comprises the following steps:
defining a Node type variable and an int type variable;
defining a constructor and two corresponding incoming parameters in Error, wherein one incoming parameter is a Node type and corresponds to a Node with a syntax Error in DOMdoc, and the other incoming parameter is an int type and corresponds to a character string length represented by a content variable;
and defining related assignment statements for Node type variables and int type variables in the constructor.
Preferably, in S1, the parsing method of the XML Document is configured to parse in a dom (Document Object model) manner, and the type of the parsed Document is a Document type;
copying the analytic document DOMdoc to obtain a cloned analytic document docClone;
the docClone calls the clonenode (true) method to acquire via DOMdoc.
Preferably, an error handling class handleError is further defined in S2, so as to implement a domerrorrandler interface through the handleError, and an error handling function is defined in the handleError;
acquiring a DOMConfiguration object of the docClone, and setting related parameters for the object;
wherein, the defining process of the error processing function comprises the following steps:
s21, an error handling function has an incoming parameter err of DOMERror type;
s22, defining a variable loc of the DOMLocator type, and assigning the value obtained by the err calling getLocation () method to the loc;
s23, instantiating the grammar Error into an Error object and storing the Error object in errors variable for Error information tracking;
s24, judging the grammar error type;
and S25, updating the error information to output the error information.
Preferably, in S23, the process of instantiating the Error object with the syntax Error includes:
s231, finding a corresponding node in the DOMdoc according to the syntax error node of the docClone document;
s232, calling an Error class constructor and taking node and content.length () as incoming parameters to obtain an Error object;
in S24, the syntax ERROR includes three types, namely, domer, server _ WARNING, domer, server _ ERROR, and domer, server _ fault _ ERROR, where the ERROR obtains the current syntax ERROR type by calling the getsensitivity () method, and updates the content according to the ERROR type;
and in S24, err acquires error information by calling the getMessage method, and updates the error information to the content.
Preferably, wherein in S3, the error information output is configured to be used in a text form or an information output panel;
defining a JFrame in GUI programming, embedding a JEditorpane in the JFrame, calling a setText () method through the JEditorpane, using the content for storing error information as the content of the JEditorpane, and matching an error tracking function to realize error position tracking.
Preferably, in S4, the error location tracking function is a mouse click event function of JEditorPane, and when the mouse clicks the error information output on JEditorPane, the syntax error location is tracked according to the error information.
Preferably, the mouse click event function definition process is as follows:
s41, the function has an incoming parameter e of the MouseEvent type;
s42, defining three int type variables position, p1, p2 and a Node type variable Node in a mouse click event function;
s43, determining error information of mouse click according to the relevant variables, and assigning error objects corresponding to the error information in the errors variables to the relevant variables;
s44, selecting the error information on JEditorpane according to the related variable;
and S45, finding out the nodes with grammar errors in the DOMdoc according to the relevant variable values.
Preferably, in S42, the position corresponds to a click position of the mouse on the JEditorPane, and the value is obtained by the JEditorPane calling a viewmodel (e.getpoint ()) method;
the initial values of p1 and p2 are 0;
the node has an initial value of null.
Preferably, in S44, the process of selecting the error message according to the related variable on the JEditorPane includes:
s441, determining whether p2 is true, and if true, assigning the length value of the character string indicated by the content variable to p 2;
s442, the JEditorpane calls setCardPosition (p1) and moveCardPosition (p2) methods to select error information at a mouse click position on the JEditorpane;
in S45, the node obtained in S43 is a node corresponding to the syntax error information selected by mouse click, the node is found in DOMdoc, and the node is displayed in a manner different from other nodes.
The invention at least comprises the following beneficial effects: firstly, when the grammar error exists in the XML document, the error information can be output in a segmentation mode, and different errors can be distinguished conveniently.
Secondly, in practical application, error information tracking is supported, namely, the error position can be quickly found by clicking grammar error information.
Additional advantages, objects, and features of the invention will be set forth in part in the description which follows and in part will become apparent to those having ordinary skill in the art upon examination of the following or may be learned from practice of the invention.
Drawings
FIG. 1 is a schematic flow chart of an XML Schema-based XML verification method according to the present invention;
FIG. 2 is a schematic flow chart of parsing an XML document based on DOM and obtaining a clone document of the parsed document according to the present invention;
FIG. 3 is a flowchart illustrating the error type determination according to the present invention;
FIG. 4 is a schematic diagram illustrating a process of searching for a corresponding node in an XML parsing document according to a syntax error node of a clone document according to the present invention.
Detailed Description
The present invention is further described in detail below with reference to the attached drawings so that those skilled in the art can implement the invention by referring to the description text.
It will be understood that terms such as "having," "including," and "comprising," as used herein, do not preclude the presence or addition of one or more other elements or groups thereof.
The implementation form of the method for verifying the XML document based on the XML Schema comprises the following steps:
s1, the Java language realizes DOM programming interface, analyzes XML document to obtain corresponding analysis document DOMdoc, firstly realizes DOM programming interface through Java language to existing XML document to obtain analyzer example, then calls relative method to analyze XML document through analyzer example by using URL path of XML document as outgoing parameter to obtain analysis document (named DOMdoc for convenient subsequent description);
s2, carrying out integrity check on the DOMdoc of the analysis document to judge whether grammatical errors exist, wherein the XML Schema can be used for designing, restraining and verifying the XML document, and the integrity check is carried out on the XML Schema document in the prior art;
s3, outputting error information, and outputting the error information after verification to facilitate later modification;
s4, defining a tracking function of the error position;
the tracking function determines error information according to the mouse clicking position, finds a node corresponding to the error information in the DOMdoc, and displays the node in a mode different from other nodes, wherein the specific implementation mode depends on the display mode of the DOMdoc document. The method realizes the positioning of the error information in the XML Schema document through a tracking function so as to modify the corresponding error information.
Specifically, fig. 1 is a schematic flow chart of an XML verification method based on XML Schema, and it can be seen from the diagram that:
step 101, XML document
Step 102, DOM parses the XML file, obtains the parsed document (DOMdoc)
Firstly, a DOM programming interface is realized, and a resolver instance is obtained. Then, the URL path of the XML file is taken as an outgoing parameter, and the parser instance calls a related method to parse the XML file to obtain a parsed document (named DOMdoc for facilitating subsequent description).
Step 103, obtaining DOMdoc clone document docClone, and obtaining DOMConfiguration object (config) of docClone
DOMdoc calls the cloneNode () method to get DOMdoc clone document (named docClone), docClone calls the getDOMConfig () method to get the DOMConfiguration object of the docClone document.
Step 104, setting parameters for config
The config Object calls the setParameter (String name, Object value) method, the name value is "schema-type", the value is "http:// www.w3. org/2001/XMLSchema";
the config Object calls a setname (Object value) method, the name value is 'Schema-location', and the value is the URL path of the XML Schema document;
the config Object calls setname (Object value) method, the name value is "valid", and the value is true;
the config Object calls setname (Object value) method, the name value is "error-handler", and the value is the instantiation Object of handleError;
step 105, integrity check
Step 106, judging whether grammar error exists
If there is a syntax error, go to step 108; if there is no syntax error, go to step 107.
Step 107, file grammar correction
And the XML document is subjected to XML Schema grammar verification, and no grammar error exists.
Step 108, error information output
And acquiring the grammar error and outputting grammar error information.
Step 109, error information tracking
And determining error information according to the mouse clicking position, finding a node corresponding to the error information in the DOMdoc, and displaying the node in a mode different from other nodes, wherein the specific implementation mode depends on the display mode of the DOMdoc document.
Therefore, by adopting the scheme, the correctness of the grammar of the XML document can be verified based on the XML Schema, the error information output and the error information tracking are supported in specific application, data editors can conveniently know the error reason and quickly find the grammar error position so as to accurately and quickly modify the grammar error, and the method has the advantages of good implementable effect, strong operability and good adaptability. Also, this manner is merely an illustration of a preferred example, but not limited thereto. When the invention is implemented, appropriate replacement and/or modification can be carried out according to the requirements of users.
In another example, in S1, an Error class Error and related variables are further defined, and the Error type and the Error information are classified and output through cooperation of the defined Error class and related variables;
wherein the definition of the relevant variables comprises:
a String type variable content for storing error information, an initial value of which is configured as an empty String;
another variable Error for holding ArrayList < Error > type created for syntax errors present in XML document;
the establishment of the Error includes defining two corresponding variables:
defining a Node type variable (named Node) and an int type variable (named p 1);
defining a constructor and two corresponding incoming parameters in Error, wherein one incoming parameter is a Node type and corresponds to a Node with a syntax Error in DOMdoc, and the other incoming parameter is an int type and corresponds to a character string length represented by a content variable;
defining related assignment statements for Node type variables and int type variables in a constructor, specifically assigning the introduced parameters of the Node type to the Node variables defined in the Error class; the incoming parameter of int type is assigned to the p1 variable defined in Error class. The method is adopted to classify the types of the errors and define the corresponding variables so as to classify and output the error information, and has the advantages of good implementable effect and good stability. Also, this manner is merely an illustration of a preferred example, but not limited thereto. When the invention is implemented, appropriate replacement and/or modification can be carried out according to the requirements of users.
In another example, in S1, the parsing manner of the XML Document is configured to parse in a dom (Document Object model) manner, and the type of the parsed Document is Document type;
copying the DOMdoc of the analytic document to obtain a cloned analytic document docClone, wherein the copying and copying function of the analytic document is to copy and copy the analytic document so as not to damage the integrity of the original document during verification and prevent the analytic document from being damaged during verification or later operation;
the docClone calls the clonenode (true) method to acquire via DOMdoc.
Specifically, fig. 2 is a schematic flow chart of the present invention for parsing an XML document based on DOM and obtaining a clone document of the parsed document, and it can be seen from the diagram that the process of cloning the document includes:
step 201, obtaining the URL path of the XML document.
Step 202, the Java language realizes a DOM programming interface and acquires a parser instance.
And step 203, analyzing the XML Schema document to obtain an analyzed document (named DOMdoc).
And taking the URL path of the XML Document as an incoming parameter, calling a pars (URL URL) method by the parser instance to parse the XML Document, and assigning a parsing result to the DOMdoc variable of the Document type.
And step 204, cloning the DOMdoc document to obtain a clone document (docClone).
And the DOMdoc calls a cloneNode () method to obtain a DOMdoc clone Document, and assigns a clone result to a docClone variable of the Document type.
By adopting the scheme, the XML analysis document is obtained and copied, and then the integrity of the copied document is verified, so that the integrity and the stability of the original document are ensured while the copied document is verified, and the method has the advantages of good implementable effect, strong operability and good stability. Also, this manner is merely an illustration of a preferred example, but not limited thereto. When the invention is implemented, appropriate replacement and/or modification can be carried out according to the requirements of users.
In another example, an error handling class handleError needs to be defined in S2, so as to implement a domerrorrandler interface through the handleError and define an error handling function in the handleError;
acquiring a DOMConfiguration object of the docClone, and setting related parameters for the object; in S2, docClone acquires its DOMConfiguration object config by calling getDomConfig () method;
the process of setting relevant parameters for the config object includes:
the config Object calls the setParameter (String name, Object value) method, the name value is "schema-type", the value is "http:// www.w3. org/2001/XMLSchema";
the config Object calls a setname (Object value) method, the name value is 'Schema-location', and the value is the URL path of the XML Schema document;
the config Object calls setname (Object value) method, the name value is "valid", and the value is true;
the config Object calls setname (Object value) method, the name value is "error-handler", and the value is the instantiation Object of handleError;
wherein, the defining process of the error processing function comprises the following steps:
s21, an error handling function has an incoming parameter err of DOMERror type;
s22, defining a variable loc of the DOMLocator type, and assigning the value obtained by the err calling getLocation () method to the loc;
s23, instantiating the grammar Error into an Error object and storing the Error object in errors variable for Error information tracking;
s24, judging the grammar error type;
and S25, updating the error information to output the error information.
Specifically, fig. 3 is a schematic flow chart of the error type determination of the present invention, and it can be seen from the diagram that it includes:
step 301, obtaining DOMERror instance (err)
For ease of description, the DOMError example is named err.
Step 302, obtain error type
err calls getSeverity () method to get the error type.
Step 303, determining the error type
If the error is of the "DOMERror. SEVERITY _ WARNING" type, go to step 304; if the ERROR is of the "DOMERror. SEVERITY _ ERROR" type, go to step 305; if the ERROR is of the type "DOMERror. SEVERITY _ FATAL _ ERROR", then step 306 is performed.
Step 304, DOMERror. SEVERITY _ WARNING
If the error is of the type, step 307 is executed.
Step 305, domerrer
If the error is of the type, step 308 is performed.
Step 306, DOMERror. SEVERITY _ FATAL _ ERROR
If the error is of this type, step 309 is performed.
Step 307, content is updated, and the content is updated by' warning: "is added to the character string represented by the content.
The character string indicated by the content stores information that an error occurred during the verification process, and the content is "warning: "add to content," indicating the syntax error type, step 310 is performed.
Step 308, updating the content, and setting' error: "is added to the character string represented by the content.
The character string indicated by the content stores information of errors occurring in the verification process, and the value of "error: "add to content," indicating the syntax error type, step 310 is performed.
Step 309, updating the content, and comparing the' faral error: "is added to the character string represented by the content.
The character string indicated by the content stores information that an error occurred during the verification process, and the "total error: "add to content," indicating the syntax error type, step 310 is performed.
And step 310, updating the content, acquiring error information, adding the error information into the character string represented by the content, calling a getMessage () method by an err to acquire the syntax error detailed information, and adding the information into the content. This information constitutes a complete piece of syntax error information with the content updated in the content in the previous step. By adopting the scheme, the error handling class is further customized, so that the method has better adaptability, can update the current state of the error information in time to meet the requirements of document verification and later modification, and has the advantages of good implementable effect, strong operability and good stability. Also, this manner is merely an illustration of a preferred example, but not limited thereto. When the invention is implemented, appropriate replacement and/or modification can be carried out according to the requirements of users.
In another example, in S23, the process of instantiating the Error object with the syntax Error includes:
s231, finding a corresponding node in the DOMdoc according to the syntax error node of the docClone document;
s232, calling an Error class constructor and taking node and content.length () as incoming parameters to obtain an Error object;
in S24, the syntax ERROR includes three types, namely, domer, server _ WARNING, domer, server _ ERROR, and domer, server _ fault _ ERROR, where the ERROR obtains the current syntax ERROR type by calling the getsensitivity () method, and updates the content according to the ERROR type;
and in S24, err acquires error information by calling the getMessage method, and updates the error information to the content.
By adopting the scheme, the error information is acquired, and the types of the error information are classified so as to be output as required, so that an operator can conveniently acquire and modify the operation, and the method has the advantages of good implementable effect, strong operability and good adaptability. Also, this manner is merely an illustration of a preferred example, but not limited thereto. When the invention is implemented, appropriate replacement and/or modification can be carried out according to the requirements of users.
In another example, in S3, the error message output is configured to take the form of text or a message output panel;
defining a JFrame in GUI programming, embedding a JEditorpane in the JFrame, calling a setText () method through the JEditorpane, using the content for storing error information as the content of the JEditorpane, and matching an error tracking function to realize error position tracking. By adopting the scheme, the method is detailed in a mode of tracking the position of the error information, so that the aim of the invention is achieved, and the method has the advantages of good implementable effect and stronger operability. Also, this manner is merely an illustration of a preferred example, but not limited thereto. When the invention is implemented, appropriate replacement and/or modification can be carried out according to the requirements of users.
In another example, in S4, the error location tracking function is a mouse click event function of JEditorPane, and when a mouse clicks the error information output on JEditorPane, the syntax error location is tracked according to the error information. By adopting the scheme, the method for tracking the grammar error position of the error information of the user is detailed, so that the method has the advantages of better tracking effect and better stability. Also, this manner is merely an illustration of a preferred example, but not limited thereto. When the invention is implemented, appropriate replacement and/or modification can be carried out according to the requirements of users.
In another example, the mouse click event function definition process is:
s41, the function has an incoming parameter e of the MouseEvent type;
s42, defining three int type variables position, p1, p2 and a Node type variable Node in a mouse click event function;
s43, determining error information of mouse click according to the related variables, assigning error objects corresponding to the error information in the error variables to the related variables, determining error information of mouse click according to the related variables, and assigning the error objects corresponding to the error information in the error variables to the related variables, the steps are as follows:
Figure BDA0001728243170000121
s44, selecting the error information on JEditorpane according to the related variable;
and S45, finding out the nodes with grammar errors in the DOMdoc according to the relevant variable values.
Specifically, fig. 4 is a schematic flow chart of the present invention for finding a corresponding node in an XML parsing document according to a syntax error node of a clone document, and it can be seen from the diagram that:
step 401, obtaining a node (n1) with syntax error in the docClone; defining a variable (num) of ArrayList < Integer > type
The DOMERror instance err calls the getLocation () method to instantiate the DOMLocator, and an instantiation object is obtained and named loc. loc calls getRelatedNode () method to get the node with syntax error named n1. Step 402 is performed.
Step 402, determining whether (n1 | & & n1.getnodetype () | NODE
If true, go to step 403; if false, go to step 404;
step 403, obtain the previous sibling node of n1 (n2)
n1 calls getproviousslocking () method to get the previous sibling node of n1, named n2, and step 405 is performed.
Step 404, define a Node type variable (n3, initial value DOMdoc)
A Node type variable is defined, named n3, DOMdoc is assigned to n3, and step 410 is performed.
Step 405, define a variable of int type (i, initial value 0)
Define a variable of int type, named i, with an initial value of 0, go to step 406.
Step 406, determine if n2 is empty
If it is empty, go to step 407; if not, go to step 408;
step 407, add i to num
num calls add () method to add i to num, and step 409 is performed.
Step 408, the variable i is incremented by 1 and n2 is replaced with the previous sibling of n2
n2 calls getproviousslocking () method to get the previous sibling node of n2 and assigns the node to n2, and step 406 is performed.
Step 409, replace n1 with the parent of n1
n1 calls getpointnode () method to get the parent node of n1 and assigns it to n1, executing step 402.
Step 410, define a variable of int type (j, initial value num. size ())
Define a variable of int type, named j, assign num.
Step 411, determining whether (j > -1) is true
If true, go to step 412; if false, go to step 413.
Step 412, replace n3 with the first child node of n3
n3 calls getFirstchild () method to get the first child node of n3 and assign it to n3, go to step 414.
Step 413, obtain n3
n3 is the node in DOMdoc that corresponds to the presence of syntax error in docClone.
Step 414, define a variable (k, initial value num. get (i-1))
Define a variable of int type, named k, assign num.get (i-1) to k, perform step 415.
Step 415, define a variable of int type (m, initial value is 0)
A variable of int type is defined, named m, and assigned 0 to m, step 416 is performed.
Step 416, determine if (m < k) is true
If true, go to step 417; if false, step 418 is performed.
Step 417, the variable m is incremented by 1 and the next sibling of n3 is substituted for n3
n3 calls getNextSibling () method to get the next sibling node of n3 and replace n3 with that node, go to step 416.
Step 418, the variable j is self-reduced by 1
The variable j is decremented by 1 and step 411 is performed.
The scheme is only a software implementation mode of one implementation mode, and has the advantages of good implementable effect, simplicity and easiness. Also, this manner is merely an illustration of a preferred example, but not limited thereto. When the invention is implemented, appropriate replacement and/or modification can be carried out according to the requirements of users.
In another example, in S42, the position corresponds to the click position of the mouse on the JEditorPane, and the value is obtained by the JEditorPane calling the viewmodel (e.getpoint ()) method;
the initial values of p1 and p2 are 0;
the node has an initial value of null. The scheme is adopted to further limit the mode, so that the method has the advantages of good implementation effect, simplicity and feasibility. Also, this manner is merely an illustration of a preferred example, but not limited thereto. When the invention is implemented, appropriate replacement and/or modification can be carried out according to the requirements of users.
In another example, in S44, the process of selecting the error message according to the related variable on the JEditorPane includes:
s441, determining whether p2 is true, and if true, assigning the length value of the character string indicated by the content variable to p 2;
s442, the JEditorpane calls setCardPosition (p1) and moveCardPosition (p2) methods to select error information at a mouse click position on the JEditorpane;
in S45, the node obtained in S43 is a node corresponding to the syntax error information selected by mouse click, the node is found in DOMdoc, and the node is displayed in a manner different from other nodes. By adopting the scheme, the final position of the error information is accurately positioned through the corresponding transformation of the nodes, so that the method has the advantages of high positioning accuracy and simpler modification. Also, this manner is merely an illustration of a preferred example, but not limited thereto. When the invention is implemented, appropriate replacement and/or modification can be carried out according to the requirements of users.
The number of apparatuses and the scale of the process described herein are intended to simplify the description of the present invention. Application, modifications and variations of the method of validating an XML document based on an XML Schema of the present invention will be apparent to those skilled in the art.
While embodiments of the invention have been disclosed above, it is not intended to be limited to the uses set forth in the specification and examples. It can be applied to all kinds of fields suitable for the present invention. Additional modifications will readily occur to those skilled in the art. It is therefore intended that the invention not be limited to the exact details and illustrations described and illustrated herein, but fall within the scope of the appended claims and equivalents thereof.

Claims (9)

1. A method for verifying XML documents based on XML Schema is characterized by comprising the following steps:
s1, realizing a DOM (document object model) programming interface by using the Java language, and analyzing the XML document to obtain a corresponding analyzed document DOMdoc;
s2, carrying out integrity check on the DOMdoc of the analysis document to judge whether a grammar error exists;
s3, outputting error information;
s4, defining an error position tracking function;
the tracking function determines error information according to the mouse clicking position, finds a node corresponding to the error information in the DOMdoc, and displays the node in a mode different from other nodes, wherein the specific implementation mode depends on the display mode of the DOMdoc document;
in S1, an Error class Error and related variables are defined;
wherein the definition of the relevant variables comprises:
a String type variable content for storing error information, an initial value of which is configured as an empty String;
another variable Error for holding ArrayList < Error > type created for syntax errors present in XML document;
the establishment of the Error comprises the following steps:
defining a Node type variable and an int type variable;
defining a constructor and two corresponding incoming parameters in Error, wherein one incoming parameter is a Node type and corresponds to a Node with a syntax Error in DOMdoc, and the other incoming parameter is an int type and corresponds to a character string length represented by a content variable;
and defining related assignment statements for Node type variables and int type variables in the constructor.
2. The method according to claim 1, wherein in S1, the parsing mode of the XML Document is configured to parse in dom (Document Object model), and the type of the parsed Document is Document type;
copying the analytic document DOMdoc to obtain a cloned analytic document docClone;
the docClone calls the clonenode (true) method to acquire via DOMdoc.
3. The method for validating an XML document according to XML Schema as claimed in claim 1, wherein an error handling class handleError needs to be defined in S2, so as to implement a domerrorrandler interface through the handleError and define an error handling function in the handleError;
acquiring a DOMConfiguration object of the docClone, and setting related parameters for the object;
wherein, the defining process of the error processing function comprises the following steps:
s21, an error handling function has an incoming parameter err of DOMERror type;
s22, defining a variable loc of the DOMLocator type, and assigning the value obtained by the err calling getLocation () method to the loc;
s23, instantiating the grammar Error into an Error object and storing the Error object in errors variable for Error information tracking;
s24, judging the grammar error type;
and S25, updating the error information to output the error information.
4. The method for validating an XML document based on an XML Schema as claimed in claim 3, wherein the process of instantiating the Error object with the syntax Error in S23 includes:
s231, finding a corresponding node in the DOMdoc according to the syntax error node of the docClone document;
s232, calling an Error class constructor and taking node and content.length () as incoming parameters to obtain an Error object;
in S24, the syntax ERROR includes three types, namely, domer, server _ WARNING, domer, server _ ERROR, and domer, server _ fault _ ERROR, where the ERROR obtains the current syntax ERROR type by calling the getsensitivity () method, and updates the content according to the ERROR type;
and in S24, err acquires error information by calling the getMessage method, and updates the error information to the content.
5. A method of validating an XML document according to claim 1, wherein in S3, the error message output is configured to be used in a text form or in a message output panel;
defining a JFrame in GUI programming, embedding a JEditorpane in the JFrame, calling a setText () method through the JEditorpane, using the content for storing error information as the content of the JEditorpane, and matching an error tracking function to realize error position tracking.
6. The method for validating an XML document based on XML Schema as claimed in claim 1, wherein in S4, the error location tracking function is a mouse click event function of JEditorPane, and when a mouse clicks the error information outputted on the JEditorPane, the syntax error location is tracked according to the error information.
7. The method for validating an XML document based on an XML Schema as claimed in claim 6, wherein the mouse click event function definition process is:
s41, the function has an incoming parameter e of the MouseEvent type;
s42, defining three int type variables position, p1, p2 and a Node type variable Node in a mouse click event function;
s43, determining error information of mouse click according to the relevant variables, and assigning error objects corresponding to the error information in the errors variables to the relevant variables;
s44, selecting the error information on JEditorpane according to the related variable;
and S45, finding out the nodes with grammar errors in the DOMdoc according to the relevant variable values.
8. The method for validating an XML document based on XML Schema as claimed in claim 7, wherein in S42, the position corresponds to a click position of a mouse on the JEditorPane, and the value is obtained by the JEditorPane calling a viewmodel (e.getpoint ()) method;
the initial values of p1 and p2 are 0;
the node has an initial value of null.
9. The method for validating an XML document based on XML Schema as claimed in claim 7, wherein the step of checking the error message according to the related variable in the JEditorPane at S44 includes:
s441, determining whether p2 is true, and if true, assigning the length value of the character string indicated by the content variable to p 2;
s442, the JEditorpane calls setCardPosition (p1) and moveCardPosition (p2) methods to select error information at a mouse click position on the JEditorpane;
in S45, the node obtained in S43 is a node corresponding to the syntax error information selected by mouse click, the node is found in DOMdoc, and the node is displayed in a manner different from other nodes.
CN201810762652.7A 2018-07-12 2018-07-12 Method for verifying XML document based on XML Schema Active CN108959095B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810762652.7A CN108959095B (en) 2018-07-12 2018-07-12 Method for verifying XML document based on XML Schema

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810762652.7A CN108959095B (en) 2018-07-12 2018-07-12 Method for verifying XML document based on XML Schema

Publications (2)

Publication Number Publication Date
CN108959095A CN108959095A (en) 2018-12-07
CN108959095B true CN108959095B (en) 2021-11-23

Family

ID=64483665

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810762652.7A Active CN108959095B (en) 2018-07-12 2018-07-12 Method for verifying XML document based on XML Schema

Country Status (1)

Country Link
CN (1) CN108959095B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111984739A (en) * 2019-05-24 2020-11-24 中移(苏州)软件技术有限公司 Conversion method, terminal and storage medium for XML and relational database
CN110611713A (en) * 2019-09-17 2019-12-24 深圳市网心科技有限公司 Data downloading method and system, electronic equipment and storage medium
CN111324844A (en) * 2020-02-20 2020-06-23 重庆锐云科技有限公司 Data export control method and device, marketing management platform and storage medium
CN112784112B (en) * 2021-01-29 2023-06-27 银清科技有限公司 Message verification method and device
CN113822024A (en) * 2021-09-24 2021-12-21 杭州同泽信息技术服务有限公司 Method and device for supporting multi-person online editing of financial document and verifying authenticity

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1472645A (en) * 2002-06-27 2004-02-04 System and method for verifying extendable label language files and reporting contrary mode against them in real time
CN101101602A (en) * 2007-07-27 2008-01-09 华为技术有限公司 Data format verification method and device
CN101808073A (en) * 2009-02-13 2010-08-18 华为技术有限公司 Method for acquiring node information, server and system thereof
CN102402556A (en) * 2010-09-16 2012-04-04 深圳市金蝶中间件有限公司 XML (extensive makeup language) file checking method and device
CN102646039A (en) * 2012-02-29 2012-08-22 河海大学 Software interface generating system and method based on extensible markup language (XML) Schema
CN105160590A (en) * 2015-07-24 2015-12-16 国家电网公司 Extensible markup language (XML) based information interoperability verification method in high-speed model intelligent power distribution and consumption field
CN105354181A (en) * 2015-09-24 2016-02-24 四川长虹电器股份有限公司 XBRL document checking and error correction positioning method

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101263459A (en) * 2004-10-01 2008-09-10 迪堡公司 A graphical XML programming system and engine
US8078961B2 (en) * 2008-04-03 2011-12-13 Xerox Corporation SGML document validation using XML-based technologies
CN101634982A (en) * 2008-07-24 2010-01-27 国际商业机器公司 Method and system used for verifying XML document
US20150278386A1 (en) * 2014-03-25 2015-10-01 Syntel, Inc. Universal xml validator (uxv) tool

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1472645A (en) * 2002-06-27 2004-02-04 System and method for verifying extendable label language files and reporting contrary mode against them in real time
CN101101602A (en) * 2007-07-27 2008-01-09 华为技术有限公司 Data format verification method and device
CN101808073A (en) * 2009-02-13 2010-08-18 华为技术有限公司 Method for acquiring node information, server and system thereof
CN102402556A (en) * 2010-09-16 2012-04-04 深圳市金蝶中间件有限公司 XML (extensive makeup language) file checking method and device
CN102646039A (en) * 2012-02-29 2012-08-22 河海大学 Software interface generating system and method based on extensible markup language (XML) Schema
CN105160590A (en) * 2015-07-24 2015-12-16 国家电网公司 Extensible markup language (XML) based information interoperability verification method in high-speed model intelligent power distribution and consumption field
CN105354181A (en) * 2015-09-24 2016-02-24 四川长虹电器股份有限公司 XBRL document checking and error correction positioning method

Non-Patent Citations (5)

* Cited by examiner, † Cited by third party
Title
Incremental Validation of XML Document Based on Simplified XML Element Sequence Pattern;Boshi Sun 等;《2010 Seventh Web Information Systems and Applications Conference》;20100923;第110-114页 *
Research on XML Schema Transformation Algorithm;Bin JI.etc;《2017 2nd International Conference on Communications,Information Management and Network Security》;20171022;第267-271页 *
一种XML解析器技术的研究与实现;曹风华;《微型机与应用》;20111110;第30卷(第21期);第4-10页 *
基于XML Schema抽象模型的XML模式验证方法;王伟良 等;《计算机应用与软件》;20070330;第24卷(第03期);第41-60页 *
基于XML Schema的知识描述与模式验证;许桂艳 等;《计算机系统应用》;20080915(第09期);第33-37页 *

Also Published As

Publication number Publication date
CN108959095A (en) 2018-12-07

Similar Documents

Publication Publication Date Title
CN108959095B (en) Method for verifying XML document based on XML Schema
US9864586B2 (en) Code quality improvement
US8200780B2 (en) Multiple bindings in web service data connection
US9900209B2 (en) Techniques for YANG model version control validation
US9734044B2 (en) Automatic test case generation
US7272822B1 (en) Automatically generating software tests based on metadata
US7039833B2 (en) Stack trace generated code compared with database to find error resolution information
US8413041B2 (en) Apparatus and method for parsing XML document by using external XML validator
US8136095B2 (en) Relations in fuzzing data
US6802059B1 (en) Transforming character strings that are contained in a unit of computer program code
US20090019313A1 (en) System and method for performing client-side input validation
US20160004517A1 (en) SOFTWARE DEVELOPMENT IMPROVEMENT TOOL - iREVIEW
US20190272157A1 (en) System and method for embedding domain-specific language code within a visualization of cloud-based computing infrastructure
CN110933095A (en) Message parsing method and device
US20200293541A1 (en) Methods, systems, and computer readable media for data translation using a representational state transfer (rest) application programming interface (api)
US11010287B1 (en) Field property extraction and field value validation using a validated dataset
CN111428132B (en) Data verification method and device, computer storage medium and electronic equipment
CN111581920A (en) Document conversion method, device, equipment and computer storage medium
US20130036108A1 (en) Method and system for assisting users with operating network devices
US20150278386A1 (en) Universal xml validator (uxv) tool
US20060271817A1 (en) System and method for error checking of failed I/O open calls
CN110413518B (en) Control object library generation method and device and computer readable storage medium
CN110188432B (en) System architecture verification method, electronic device and computer-readable storage medium
CN116708270A (en) Automatic generation method of front-end route
US20210026608A1 (en) Compile time validation of programming code

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant