惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 风满袖

如何进行有效的沟通(二) 如何进行有效的沟通(一) SOA——概念 (转)Locale 详解 在Weblogic8.1.4服务器上安装Alphablox8.4 BI相关的术语 开源BI系统简述 如何收集项目需求 Prefactoring——Guidelines Prefactoring——Introduction Create C++ Object Dynamically MVP——Model-Viewer-Presenter Success/Failure Criteria for Software Projects AJAX Secutiry and AJAX Applications Accessible -- Many Tutorials and Articles A NHibernate Helper Kit Apache——Config WebDAV 3D Desktop Some Funny Development Methodologies -- XXX Driven Development Why I hate Web 2.0/AJAX? Here are some reasons...
A XMLBean Tip
风满袖 · 2007-07-17 · via 博客园 - 风满袖

         XMLBean的确是一个非常方便的工具,可以根据XSD来生成Java Class,使得我们以非常舒服的面向对象的方式读写XML,比.Net世界里面的XmlDocument和XmlNode对象来得更加直观。不过,Java世界里面的文档真的是令人不敢恭维,从代码生产的粗陋的Java Doc就当作API Ref,根本不能和微软的MSDN相提并论,这在我使用Java的多种开发工具和Lib的时候,一次次地加深了这样的印象。
        前段时间我使用XMLBean来生成xml串,我的过程是这样的:1、使用XMLSpy写好XSD,然后使用XMLBean帮我生成Java Class。2、使用这些Java Class来创建Document,数据来源则是数据库 3、获得生成的document的XML String。3、适应Web Service将这些XML String发送到远程服务器。4、远程服务器会根据XSD对收到的XML进行校验,以检查是否符合规范。 结果问题来了,远程服务器(程序是另外一个公司的人写的,但使用的是相同的XSD)总是校验不通过。经过检查,我发现XMLBean生成的XML Element的节点标签和XSD中定义的并不完全一致,比如我在XSD中定义了:

<xs:element name="MyVeryLongTagName">


而生成的xml中则是

<MVLTN></MVLTN>

这样的内容,从表面上来看,XMLBean为我生成了Tag的缩写形式,而这不是我想要的。查了XMLBean的粗陋的Java Doc,试了多个API才解决了问题,现在将小Tip列出来: 保证生成的XML的Element的Tag名称和XSD中定义的名称完全一致,需要作额外的工作,如:

MyXmlDocument doc = MyXmlDocument.Factory.newInstance();
//create and set xml node value 

//set XmlOptions 
XmlOptions opt = new XmlOptions();
Map map 
= new HashMap();
map.put(
"my Xml namespace","xmlnsNameInXml");
map.put(
"my element tag name","elementTagNameInXml");
//set use implicit namespaces
opt.setSaveImplicitNamespaces(map);

//get xml string
String xmlString = doc.xmlText(opt);


这样设置了以后,XMLBean就不会自作聪明的把XSD里面我们定义的比较长的Element Tag Name和XML NS设置为比较简略的缩写名称了。