|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
用winrar打包j2ee的程序和用IDE打包应用程序是一样的。按照你的想法,你是不是也希望服务器都整合由一家公司提供呢?
声明:以下的测试是用的jdk1.4.2,xalan7.0关于以下xml文档片段:<ML:MREMLxmlns:ML="MREML">
<EnvelopEntity>
<EnvelopID>GUID2006102000002</EnvelopID>
<EnvelopVersion>1.0.1R</EnvelopVersion>
<ExchangeTime>2006-10-2513:12:10</ExchangeTime>
<SendFrom>
<SFID>SOBEY_NEWS</SFID>
<SFDescription>SOBEY旧事体系</SFDescription>
</SendFrom>
<SendTo>
<STID>DAYANG_MAM</STID>
<STDescription>DAYANG媒资体系</STDescription>
</SendTo>
<Priority>2</Priority>
<EntityInfo>
<EntityID>REQUEST_ID_01</EntityID>
<EntityType>4</EntityType>
</EntityInfo>
<EntityInfo>
<EntityID>节目GUID</EntityID>
<EntityType>3</EntityType>
</EntityInfo>
<EntityInfo>
<EntityID>办理信息实体ID</EntityID>
<EntityType>2</EntityType>
</EntityInfo>
</EnvelopEntity>
</ML:MREML>
关于上述含有定名空间的xml文档,假如想经由过程xpath查找EnvelopID的值,有两种体例:1.经由过程使用xpath的函数local-name()
如上述查找内容的xpath表达式能够写为://*[local-name()=MREML]/EnvelopEntity/EnvelopID/text()
2.经由过程在java程序中处置上述文档的定名空间是界说的,假如要使xpath表达式能准确地被剖析必要在java程序中创建起prefix和uri两者的映照干系
publicstaticNodeparseXPath(Stringexpression,Objectobj,QNameqname)
throwsException{
javax.xml.xpath.XPathxpath=javax.xml.xpath.XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(getNamespaceContext());
if(qname.equals(XPathConstants.NODE))
return(Node)xpath.evaluate(expression,obj,qname);
returnnull;
}
publicstaticNamespaceContextgetNamespaceContext()throwsException{
returnnewNamespaceContext(){
publicStringgetNamespaceURI(Stringprefix){
/*
//一种体例:
//这里能够接纳设置文件的体例,先将所必要利用的xmlNamespace设置好,
//接纳注册的体例供给用利用,这类体例效力应当高一些,不必每次都要从文档中提取namespace
//不外没有第二种便利
Stringuri;
if(prefix.equalsIgnoreCase("ML"))
uri="MREML";
elseif(prefix.equalsIgnoreCase("RE"))
uri="http://herry.com.cn";
elseif(prefix.equalsIgnoreCase("RID"))
uri="ResourceID";
elseif(prefix.equalsIgnoreCase("RUI"))
uri="ResourceUniqueID";
elseif(prefix.equalsIgnoreCase("RMDI"))
uri="ResourceMetaDataInfo";
else
uri=null;
System.out.println(ParseXMLUtil.class+"::getNamespaceURI:prefix="+prefix);
returnuri;
*/
/*
//别的一种体例:经由过程PrefixResolver来提掏出prefix和Namespace的对应干系
finalPrefixResolverresolver=
newPrefixResolverDefault(doc.getDocumentElement());
returnresolver.getNamespaceForPrefix(prefix);
*/
//Dummyimplementation-notused!
publicjava.util.IteratorgetPrefixes(Stringval){
returnnull;
}
//Dummyimplemenation-notused!
publicStringgetPrefix(Stringuri){
returnnull;
}
};
}
若要查找ResourceUniqueID的值,则xpath应当誊写为://ML:MREML/ML:ResourceEntity/RMDI:ResourceMetaDataInfo/RMDI:ResourceID/RUI:ResourceUniqueID/text()
这里的ML(prefix)和URI(MERML)等已经由过程
关于含有默许定名空间地文档假如接纳NamespaceContext的体例,行将prefix和uri已映照起来,如关于以下的文档:
<MREMLxmlns="MREML"><ResourceEntity>
<ResourceMetaDataInfo>
<ResourceIDxmlns="ResourceID">
<RUI:ResourceUniqueIDxmlns:RUI="ResourceUniqueID">节目GUID</RUI:ResourceUniqueID>
<UserDefID>UserDefID填写节目代码</UserDefID>
</ResourceID>
<Title>
<ResourceName>911旧事素材</ResourceName>
</Title>
<ResourceType>1</ResourceType>
<Subject>
<KeyWords>911打击</KeyWords>
</Subject>
<Description>
<ContentDescription>美国遭受911打击现场30S画面及同期声素材</ContentDescription>
<Column>
<ColumnName>昔日天下</ColumnName>
</Column>
</Description>
<Date>
<CreateDate>2006-10-2513:12:10</CreateDate>
</Date>
<Format>
<TotalLength>00:04:35:12</TotalLength>
<NumberofElements>2</NumberofElements>
<MarkPoint>
<StartPoint>00:00:00:05</StartPoint>
<EndPoint>00:04:35:10</EndPoint>
</MarkPoint>
</Format>
</ResourceMetaDataInfo>
</ResourceEntity>
</MREML>
若要查找ResourceUniqueID的值,则xpath应当誊写为://ML:MREML/ML:ResourceEntity/RMDI:ResourceMetaDataInfo/RMDI:ResourceID/RUI:ResourceUniqueID/text()
这里的ML(prefix)和URI(MERML)等已经由过程
if(prefix.equalsIgnoreCase("ML"))
uri="MREML";
elseif(prefix.equalsIgnoreCase("RE"))
uri="http://herry.com.cn";
elseif(prefix.equalsIgnoreCase("RID"))
uri="ResourceID";
elseif(prefix.equalsIgnoreCase("RUI"))
uri="ResourceUniqueID";
elseif(prefix.equalsIgnoreCase("RMDI"))
uri="ResourceMetaDataInfo";
else
uri=null;
映照。
个中的ML和RMDI都是defaultnamespace,它的感化局限包括它的子元素,直至有新的defaultnamespace呈现为止。而namespace只对它本身起感化。如将上述文档中:<ResourceMetaDataInfo>
<ResourceIDxmlns="ResourceID">
改成:
<RMDI:ResourceMetaDataInfoxmlns:RMDI=”ResourceMetaDataInfo”>
<ResourceID>
…
…
</RMDI:ResourceMetaDataInfo>
查找ResourceUniqueID的值,则xpath应当改成://ML:MREML/ML:ResourceEntity/RMDI:ResourceMetaDataInfo/ResourceID/RUI:ResourceUniqueID/text()
人人也可参考这篇文章:
http://blog.davber.com/2006/09/17/xpath-with-namespaces-in-java/
Java的B/s开发是通常是javaweb开发,又叫J2EE开发,J2SE是手机开发。C#的C/s和B/s开发是说.net网页编程和Asp开发。。u在这里说明一点;资深一点的Java和C#程序员都明白一点 |
|