¶ÔÓÚ´øÓбí¿Õ¼äxmlnsµÄxmlÎļþµÄ½âÎö
¶ÔÓÚ´øÓбí¿Õ¼äxmlnsµÄxmlÎļþµÄ½âÎö£¬ÓÃÕý³£½âÎöÎļþµÄ·½·¨×ÜÊÇʧЧ£¬²»Æð×÷Óã¬ÎÞ·¨»ñµÃÔªËØ¡£
ÏÂÃæ¸ø³öÁ½ÖÖ·½·¨½âÎö´ËÀàÎļþ£º
1.°´Õý³£½âÎöxmlÎļþµÄ·½·¨£¬ÐèҪעÒ⼸µã£º
»ñÈ¡ÔªËØElement£¬²»¿ÉʹÓú¯Êý£ºdocument.selectNodes("//region");
Ö»¿ÉÒÔÏÈÈ¡µ½¸ùÔªËØ£¬Ò»¼¶Ò»¼¶ÍùÏÂÈ¡£¬eg£º
Element root = document.getRootElement();
Element ele = root.element("head");
»ñÈ¡ÊôÐÔÖµ£¬¿ÉÒÔ°´Ò»°ãµÄ·½·¨²Ù×÷£¬eg£º
List ll = document.selectNodes("//@regionName");
System.out.println("ll.size=" + ll.size());
2.ʹÓÃXPath¡£eg:
public void testHasNameSpace(File file) {
SAXReader saxReader = new SAXReader();
Document document = null;
// XmlDocument document=
try {
document = saxReader.read(file);
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HashMap xmlMap = new HashMap();
xmlMap.put("smil", "http://www.w3.org/2000/SMIL20/CR/Language");
XPath x = document.createXPath("//smil:region");
x.setNamespaceURIs(xmlMap);
List regionList = x.selectNodes(document);
System.out.println("there are " + regionList.size() + " regions");
XPath att = document.createXPath("//smil:region/@regionName");
att.setNamespaceURIs(xmlMap);
List attrList = att.selectNodes(document);
System.out.println("there are " + attrList.size() + " attrs");
int i = 0;
Iterator it = attrList.iterator();
while (it.hasNext()) {
Attribute a = (Attribute) it.next();
System.out.println((i++) + "¸ö£º" + a.getValue());
}
}
Ïà¹ØÎĵµ£º
<!--
/* Font Definitions */
@font-face
{font-family:ËÎÌå;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:PMingLiU;
panos ......
<?xml version="1.0" encoding="utf-8" ?>
<ExamPaper Name="ÎҵĵÚÒ»ÆÚÊÔ¾í" BeginDate="2009-3-4" EndDate="2009-12-30" Scort="150" UserTime="100" FK_UserType="1" FK_AdminUser="1">
<Question PKID= ......
public partial class Form1 : Form
{
DataSet ds = new DataSet();
public Form1()
{
......
1. <?xml version="1.0" encoding="GB2312" standalone="yes" ?>
1.1 ÕâÊÇxmlµÄÎĵµÉùÃ÷£¬Ò»°ãλÓÚxmlÎļþµÄÊ×ÐС£
1.2 Êéд¹æ·¶£º<?xmlΪһÌå Ö®¼ä²»ÄÜÓпոñ¡£
1.3 encodingÊôÐÔ£¬Èç¹ ......