易语言怎么读入 xml 文件的内容
易语言怎么读入到编辑框里。。。怎么寻找里边的内容。。源码:<?xmlversion="1.0"encoding="utf-8"?><Connectorcommand="G...
易语言怎么读入到编辑框里。。。
怎么寻找里边的内容。。源码:
<?xml version="1.0" encoding="utf-8"?>
<Connector command="GetFoldersAndFiles" resourceType="Image">
<CurrentFolder path="/" url="/123/145/" />
<Folders>
<Folder name="1111" />
<Folder name="2222" />
</Folders>
<Files>
<File name="1.jpg" size="1" />
<File name="2.jpg" size="2" />
</Files>
</Connector>
读这个 /123/145/ 跟 111 222 那种!~ 展开
怎么寻找里边的内容。。源码:
<?xml version="1.0" encoding="utf-8"?>
<Connector command="GetFoldersAndFiles" resourceType="Image">
<CurrentFolder path="/" url="/123/145/" />
<Folders>
<Folder name="1111" />
<Folder name="2222" />
</Folders>
<Files>
<File name="1.jpg" size="1" />
<File name="2.jpg" size="2" />
</Files>
</Connector>
读这个 /123/145/ 跟 111 222 那种!~ 展开
3个回答
2013-05-26
展开全部
之前用java解析过xml,代码和原理告你,自己变通下
原理:
使用DOM读取XML文件
DOM解析XML文件时,会将XML文件的所有内容以文档树方式存放在内存中
代码:
package service;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import medium.Person;
public class DOMPersonService {
public List<Person> getPersons(InputStream inputStream) throws Throwable{
List<Person> persons = new ArrayList<Person>();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document document = builder.parse(inputStream);
Element root = document.getDocumentElement();
NodeList personNodes = root.getElementsByTagName("person");
for(int i = 0;i < personNodes.getLength();i++){
Person person = new Person();
Element personElement = (Element)personNodes.item(i);
person.setId(new Integer(personElement.getAttribute("id")));
NodeList personChilds = personElement.getChildNodes();
for(int j = 0;j < personChilds.getLength();j++){
if(personChilds.item(j).getNodeType()==Node.ELEMENT_NODE){
Element childElement = (Element)personChilds.item(j);
if("name".equals(childElement.getNodeName())){
person.setName(childElement.getFirstChild().getNodeValue());
}else if("age".equals(childElement.getNodeName())){
person.setAge(new Short(childElement.getFirstChild().getNodeValue()));
}
}
}
persons.add(person);
}
return persons;
}
}
原理:
使用DOM读取XML文件
DOM解析XML文件时,会将XML文件的所有内容以文档树方式存放在内存中
代码:
package service;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import medium.Person;
public class DOMPersonService {
public List<Person> getPersons(InputStream inputStream) throws Throwable{
List<Person> persons = new ArrayList<Person>();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document document = builder.parse(inputStream);
Element root = document.getDocumentElement();
NodeList personNodes = root.getElementsByTagName("person");
for(int i = 0;i < personNodes.getLength();i++){
Person person = new Person();
Element personElement = (Element)personNodes.item(i);
person.setId(new Integer(personElement.getAttribute("id")));
NodeList personChilds = personElement.getChildNodes();
for(int j = 0;j < personChilds.getLength();j++){
if(personChilds.item(j).getNodeType()==Node.ELEMENT_NODE){
Element childElement = (Element)personChilds.item(j);
if("name".equals(childElement.getNodeName())){
person.setName(childElement.getFirstChild().getNodeValue());
}else if("age".equals(childElement.getNodeName())){
person.setAge(new Short(childElement.getFirstChild().getNodeValue()));
}
}
}
persons.add(person);
}
return persons;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询