提交 bd7546cb 编写于 作者: L lihucheng
上级 39d0033d
......@@ -35,21 +35,26 @@ Converts an XML text into a JavaScript object.
| Type| Description|
| ------ | ---------------------------- |
| string | JavaScript object.|
| Object | JavaScript object.|
- Example
```
var xml =
let xml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
' <todo>Work</todo>' +
' <todo>Play</todo>' +
'</note>';
var conv = new convertxml.ConvertXML();
var result1 = conv.convert(xml, {trim: false, ignoreDeclaration: false});
console.log(result1)
let conv = new convertxml.ConvertXML();
let options = {trim : false, declarationKey:"_declaration",
instructionKey : "_instruction", attributesKey : "_attributes",
textKey : "_text", cdataKey:"_cdata", doctypeKey : "_doctype",
commentKey : "_comment", parentKey : "_parent", typeKey : "_type",
nameKey : "_name", elementsKey : "_elements"}
let result = JSON.stringify(conv.convert(xml, options));
console.log(result)
```
......@@ -57,7 +62,7 @@ Converts an XML text into a JavaScript object.
| Name| Type| Mandatory| Description|
| ----------------- | -------- | ---- | ----------------------------------------------------------- |
| trim | boolean | No| Whether to trim the whitespace characters before and after the text. The default value is **false**.|
| trim | boolean | Yes| Whether to trim the whitespace characters before and after the text. The default value is **false**.|
| ignoreDeclaration | boolean | No| Whether to ignore the XML declaration. The default value is **false**.|
| ignoreInstruction | boolean | No| Whether to ignore the XML processing instruction. The default value is **false**.|
| ignoreAttributes | boolean | No| Whether to print attributes across multiple lines and indent attributes. The default value is **false**.|
......@@ -65,14 +70,14 @@ Converts an XML text into a JavaScript object.
| ignoreCDATA | boolean | No| Whether to ignore the element's CDATA information. The default value is **false**.|
| ignoreDoctype | boolean | No| Whether to ignore the element's Doctype information. The default value is **false**.|
| ignoreText | boolean | No| Whether to ignore the element's text information. The default value is **false**.|
| declarationKey | string | No| Name of the attribute key for **declaration** in the output object. The default value is **_declaration**.|
| instructionKey | string | No| Name of the attribute key for **instruction** in the output object. The default value is **_instruction**.|
| attributesKey | string | No| Name of the attribute key for **attributes** in the output object. The default value is **_attributes**.|
| textKey | string | No| Name of the attribute key for **text** in the output object. The default value is **_text**.|
| cdataKey | string | No| Name of the attribute key for **CDATA** in the output object. The default value is **_cdata**.|
| doctypeKey | string | No| Name of the attribute key for **Doctype** in the output object. The default value is **_doctype**.|
| commentKey | string | No| Name of the attribute key for **comment** in the output object. The default value is **_comment**.|
| parentKey | string | No| Name of the attribute key for **parent** in the output object. The default value is **_parent**.|
| typeKey | string | No| Name of the attribute key for **type** in the output object. The default value is **_type**.|
| nameKey | string | No| Name of the attribute key for **name** in the output object. The default value is **_name**.|
| elementsKey | string | No| Name of the attribute key for **elements** in the output object. The default value is **_elements**.|
| declarationKey | string | Yes| Name of the attribute key for **declaration** in the output object. The default value is **_declaration**.|
| instructionKey | string | Yes| Name of the attribute key for **instruction** in the output object. The default value is **_instruction**.|
| attributesKey | string | Yes| Name of the attribute key for **attributes** in the output object. The default value is **_attributes**.|
| textKey | string | Yes| Name of the attribute key for **text** in the output object. The default value is **_text**.|
| cdataKey | string | Yes| Name of the attribute key for **CDATA** in the output object. The default value is **_cdata**.|
| doctypeKey | string | Yes| Name of the attribute key for **Doctype** in the output object. The default value is **_doctype**.|
| commentKey | string | Yes| Name of the attribute key for **comment** in the output object. The default value is **_comment**.|
| parentKey | string | Yes| Name of the attribute key for **parent** in the output object. The default value is **_parent**.|
| typeKey | string | Yes| Name of the attribute key for **type** in the output object. The default value is **_type**.|
| nameKey | string | Yes| Name of the attribute key for **name** in the output object. The default value is **_name**.|
| elementsKey | string | Yes| Name of the attribute key for **elements** in the output object. The default value is **_elements**.|
......@@ -35,21 +35,26 @@ convert(xml: string, options?: ConvertOptions) : Object
| 类型 | 说明 |
| ------ | ---------------------------- |
| string | 处理后返回的JavaScript对象。 |
| Object | 处理后返回的JavaScript对象。 |
- 示例:
```
var xml =
let xml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
' <todo>Work</todo>' +
' <todo>Play</todo>' +
'</note>';
var conv = new convertxml.ConvertXML();
var result1 = conv.convert(xml, {trim: false, ignoreDeclaration: false});
console.log(result1)
let conv = new convertxml.ConvertXML();
let options = {trim : false, declarationKey:"_declaration",
instructionKey : "_instruction", attributesKey : "_attributes",
textKey : "_text", cdataKey:"_cdata", doctypeKey : "_doctype",
commentKey : "_comment", parentKey : "_parent", typeKey : "_type",
nameKey : "_name", elementsKey : "_elements"}
let result = JSON.stringify(conv.convert(xml, options));
console.log(result)
```
......@@ -57,7 +62,7 @@ convert(xml: string, options?: ConvertOptions) : Object
| 名称 | 参数类型 | 必填 | 说明 |
| ----------------- | -------- | ---- | ----------------------------------------------------------- |
| trim | boolean | | 是否修剪位于文本前后的空白字符,默认false。 |
| trim | boolean | | 是否修剪位于文本前后的空白字符,默认false。 |
| ignoreDeclaration | boolean | 否 | 是否忽略xml写入声明指示,默认false。 |
| ignoreInstruction | boolean | 否 | 是否忽略xml的写入处理指令,默认false。 |
| ignoreAttributes | boolean | 否 | 是否跨多行打印属性并缩进属性,默认false。 |
......@@ -65,14 +70,14 @@ convert(xml: string, options?: ConvertOptions) : Object
| ignoreCDATA | boolean | 否 | 是否忽略元素的CDATA信息,默认false。 |
| ignoreDoctype | boolean | 否 | 是否忽略元素的Doctype信息,默认false。 |
| ignoreText | boolean | 否 | 是否忽略元素的文本信息,默认false。 |
| declarationKey | string | 否 | 用于输出对象中declaration的属性键的名称,默认_declaration。 |
| instructionKey | string | 否 | 用于输出对象中instruction的属性键的名称,默认_instruction。 |
| attributesKey | string | 否 | 用于输出对象中attributes的属性键的名称,默认_attributes。 |
| textKey | string | 否 | 用于输出对象中text的属性键的名称,默认_text。 |
| cdataKey | string | 否 | 用于输出对象中cdata的属性键的名称,默认_cdata。 |
| doctypeKey | string | 否 | 用于输出对象中doctype的属性键的名称,默认_doctype。 |
| commentKey | string | 否 | 用于输出对象中comment的属性键的名称,默认_comment。 |
| parentKey | string | 否 | 用于输出对象中parent的属性键的名称,默认_parent。 |
| typeKey | string | 否 | 用于输出对象中type的属性键的名称,默认_type。 |
| nameKey | string | 否 | 用于输出对象中name的属性键的名称,默认_name。 |
| elementsKey | string | 否 | 用于输出对象中elements的属性键的名称,默认_elements。 |
\ No newline at end of file
| declarationKey | string | 是 | 用于输出对象中declaration的属性键的名称,默认_declaration。 |
| instructionKey | string | 是 | 用于输出对象中instruction的属性键的名称,默认_instruction。 |
| attributesKey | string | 是 | 用于输出对象中attributes的属性键的名称,默认_attributes。 |
| textKey | string | 是 | 用于输出对象中text的属性键的名称,默认_text。 |
| cdataKey | string | 是 | 用于输出对象中cdata的属性键的名称,默认_cdata。 |
| doctypeKey | string | 是 | 用于输出对象中doctype的属性键的名称,默认_doctype。 |
| commentKey | string | 是 | 用于输出对象中comment的属性键的名称,默认_comment。 |
| parentKey | string | 是 | 用于输出对象中parent的属性键的名称,默认_parent。 |
| typeKey | string | 是 | 用于输出对象中type的属性键的名称,默认_type。 |
| nameKey | string | 是 | 用于输出对象中name的属性键的名称,默认_name。 |
| elementsKey | string | 是 | 用于输出对象中elements的属性键的名称,默认_elements。 |
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册