Java .split()方法拆分XML参数 [英] Java .split() Method To Split XML Parameters

查看:416
本文介绍了Java .split()方法拆分XML参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XML文档中的这一行:

 <?xml version =1.0encoding =UTF- 8\" >?; 
< svg xmlns:xlink =http://www.w3.org/1999/xlinkxmlns =http://www.w3.org/2000/svgcontentScriptType =text / ecmascript width =1024zoomAndPan =magnifycontentStyleType =text / cssviewBox =0 0 1024 768height =768preserveAspectRatio =xMidYMid meetversion =1.0>

我想使用拆分方法将其拆分。例如我想将每个参数保存到一个String数组中。



所以我想:

  contentScriptType =text / ecmascript
width =1024
zoomAndPan =magnify
contentStyleType =text / css
viewBox = 0 0 1024 768
height =768

等待保存一个字符串数组,有没有使用拆分方法这样做,还是有人建议一个更简单,更有效的方式来做到这一点吗?



这里是可怕的看起来正常表达式:

  \s(。*?)\s?=(?:( ?: \\ [ , '] | [^, '])+ | (?:\\ | [^ ?!])*(小于\\) |'[^ '] *' | )

Eclipse不会接受这个,因为它有无效的字符常量,任何人都知道如何克服这个错误? / p>

解决方案

使用DOM或SAX读取它,处理属性并将其添加到地图中。


I have this line from an XML document:

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" contentScriptType="text/ecmascript" width="1024" zoomAndPan="magnify" contentStyleType="text/css" viewBox="0 0 1024 768" height="768" preserveAspectRatio="xMidYMid meet" version="1.0">

I want to be able to split it up, using the split method. For example i want to save each parameter into a String array.

So i'd like:

contentScriptType="text/ecmascript" 
width="1024" 
zoomAndPan="magnify" 
contentStyleType="text/css" 
viewBox="0 0 1024 768" 
height="768"

etc etc to be saved into a string array, is there anyway to do this using the split method, or can anybody suggest an easier, more efficient way to do this?

Here is the scary looking regular expression:

\s(.*?)\s?=(?:(?:\\[,"']|[^,"'])+|"(?:\\"|[^"])*(?<!\\)"|'[^']*'|)

Eclipse wont accept this as it has invalid character constants, anybody know how to overcome this error?

解决方案

Read it with DOM or SAX, process the attributes and add it to a map.

这篇关于Java .split()方法拆分XML参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆