使用SAX处理XML Namespace
2007-11-12 14:08
501 查看
book.xml
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<?xml version="1.0" encoding="gb2312"?>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<bks:books xmlns:bks="http://www.books.org/books">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<bks:book>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<bks:title>java</bks:title>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<bks:author xmlns="http://www.books.org/people">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<name>j2ee</name>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<title>teacher</title>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</bks:author>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</bks:book>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</bks:books>
测试代码:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
package saxNS;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.io.File;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.io.FileInputStream;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.io.FileNotFoundException;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.io.IOException;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import org.xml.sax.Attributes;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import org.xml.sax.InputSource;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import org.xml.sax.SAXException;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import org.xml.sax.XMLReader;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import org.xml.sax.helpers.DefaultHandler;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import org.xml.sax.helpers.XMLReaderFactory;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public class SaxNSTest extends DefaultHandler ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public void endPrefixMapping(String prefix) throws SAXException ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println("Namespace prefix: "+prefix);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println("Namespace ending...");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public void startElement(String uri, String localName, String name,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
Attributes attributes) throws SAXException ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(!uri.equals(""))...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println("Element name:"+name);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println("Local name:"+localName);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//查看名称空间前缀
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int index=name.indexOf(":");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(index>0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println("Namespace prefix:"+name.substring(0,index));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println("NameSpace uri:"+uri);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println("---------------------");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public void startPrefixMapping(String prefix, String uri)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
throws SAXException ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println("Namespace starting...");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println("Namespace prefix: "+prefix);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println("Namespace uri: "+uri);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public static void main(String[] args) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
String realpath=System.getProperty("user.dir")+File.separator+"src"+File.separator+"saxNS"+File.separator+"book.xml";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
try ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//XMLReader缺省对名称空间进行解析
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
XMLReader reader=XMLReaderFactory.createXMLReader();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
reader.setContentHandler(new SaxNSTest());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
reader.parse(new InputSource(new FileInputStream(realpath)));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} catch (SAXException e) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// TODO Auto-generated catch block
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
e.printStackTrace();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} catch (FileNotFoundException e) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// TODO Auto-generated catch block
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
e.printStackTrace();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} catch (IOException e) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// TODO Auto-generated catch block
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
e.printStackTrace();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
结果:
Namespace starting...
Namespace prefix: bks
Namespace uri: http://www.books.org/books
Element name:bks:books
Local name:books
Namespace prefix:bks
NameSpace uri:http://www.books.org/books
---------------------
Element name:bks:book
Local name:book
Namespace prefix:bks
NameSpace uri:http://www.books.org/books
---------------------
Element name:bks:title
Local name:title
Namespace prefix:bks
NameSpace uri:http://www.books.org/books
---------------------
Namespace starting...
Namespace prefix:
Namespace uri: http://www.books.org/people
Element name:bks:author
Local name:author
Namespace prefix:bks
NameSpace uri:http://www.books.org/books
---------------------
Element name:name
Local name:name
NameSpace uri:http://www.books.org/people
---------------------
Element name:title
Local name:title
NameSpace uri:http://www.books.org/people
---------------------
Namespace prefix:
Namespace ending...
Namespace prefix: bks
Namespace ending...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<?xml version="1.0" encoding="gb2312"?>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<bks:books xmlns:bks="http://www.books.org/books">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<bks:book>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<bks:title>java</bks:title>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<bks:author xmlns="http://www.books.org/people">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<name>j2ee</name>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<title>teacher</title>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</bks:author>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</bks:book>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</bks:books>
测试代码:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
package saxNS;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.io.File;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.io.FileInputStream;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.io.FileNotFoundException;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.io.IOException;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import org.xml.sax.Attributes;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import org.xml.sax.InputSource;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import org.xml.sax.SAXException;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import org.xml.sax.XMLReader;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import org.xml.sax.helpers.DefaultHandler;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import org.xml.sax.helpers.XMLReaderFactory;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public class SaxNSTest extends DefaultHandler ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public void endPrefixMapping(String prefix) throws SAXException ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println("Namespace prefix: "+prefix);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println("Namespace ending...");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public void startElement(String uri, String localName, String name,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
Attributes attributes) throws SAXException ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(!uri.equals(""))...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println("Element name:"+name);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println("Local name:"+localName);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//查看名称空间前缀
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int index=name.indexOf(":");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(index>0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println("Namespace prefix:"+name.substring(0,index));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println("NameSpace uri:"+uri);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println("---------------------");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public void startPrefixMapping(String prefix, String uri)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
throws SAXException ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println("Namespace starting...");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println("Namespace prefix: "+prefix);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println("Namespace uri: "+uri);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public static void main(String[] args) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
String realpath=System.getProperty("user.dir")+File.separator+"src"+File.separator+"saxNS"+File.separator+"book.xml";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
try ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//XMLReader缺省对名称空间进行解析
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
XMLReader reader=XMLReaderFactory.createXMLReader();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
reader.setContentHandler(new SaxNSTest());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
reader.parse(new InputSource(new FileInputStream(realpath)));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} catch (SAXException e) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// TODO Auto-generated catch block
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
e.printStackTrace();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} catch (FileNotFoundException e) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// TODO Auto-generated catch block
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
e.printStackTrace();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} catch (IOException e) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// TODO Auto-generated catch block
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
e.printStackTrace();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
结果:
Namespace starting...
Namespace prefix: bks
Namespace uri: http://www.books.org/books
Element name:bks:books
Local name:books
Namespace prefix:bks
NameSpace uri:http://www.books.org/books
---------------------
Element name:bks:book
Local name:book
Namespace prefix:bks
NameSpace uri:http://www.books.org/books
---------------------
Element name:bks:title
Local name:title
Namespace prefix:bks
NameSpace uri:http://www.books.org/books
---------------------
Namespace starting...
Namespace prefix:
Namespace uri: http://www.books.org/people
Element name:bks:author
Local name:author
Namespace prefix:bks
NameSpace uri:http://www.books.org/books
---------------------
Element name:name
Local name:name
NameSpace uri:http://www.books.org/people
---------------------
Element name:title
Local name:title
NameSpace uri:http://www.books.org/people
---------------------
Namespace prefix:
Namespace ending...
Namespace prefix: bks
Namespace ending...
相关文章推荐
- 使用 SAX 处理 XML 文档
- [libexpat]_[XML处理]_[C/C++使用libexpat库以数据流(SAX模型)的方式读取(解析)大XML文件]
- 使用 SAX 处理 XML 文档
- 使用 SAX 处理 XML 文档
- 【Qt笔记】使用 SAX 处理 XML
- 使用 SAX 处理 XML 文档
- xml数据处理--sax模块使用
- 使用SAX处理XML文档
- 使用VTD-XML简化XML处理-克服DOM及SAX缺点的新选择
- 使用 SAX 处理 XML 解析中的错误
- 使用 SAX 处理 XML 文档(转载)
- Qt 学习之路 2(61):使用 SAX 处理 XML
- 使用SAX处理大XML文件
- 使用 SAX 处理 XML 文档(转载)
- 使用VTD-XML简化XML处理-克服DOM及SAX缺点的新选择
- [libexpat]_[XML处理]_[C/C++使用libexpat库以数据流(SAX模型)的方式读取(解析)大XML文件]
- beans.xml Caused by: org.xml.sax.SAXParseException不允许有匹配 "[xX][mM][lL]" 的处理指
- Android中使用SAX来解析XML
- MySql性能优化-通过使用XML传参将多次循环处理变为一次集合处理
- 使用minidom来处理XML的示例(Python 学习)(转载)