放置XSD的最佳场所(Best place to place XSD)
我们有一个Web服务,它接收XML字符串作为输入。 服务执行(或应该执行)的第一件事是根据预定义和约定的XML模式验证收到的XML字符串。
存储和访问此模式的最佳方法是什么?
- 与Web服务位于同一位置的物理.xsd文件?
- Web服务的代码文件中的常量字符串?
- 项目资源文件中的字符串值?
- 在网络配置的某个地方?
- 在数据库中?
我不认为选项(2)和(3)是最好的,因为架构可能会改变,然后我们需要更改代码。 然后,如果XML结构发生变化,我们还是需要更改代码才能正确解析XML。
谢谢!
We have a web service that receives an XML string as input. The first thing the service does (or should do) is validate the received XML string against a pre-defined and agreed upon XML schema.
What would be the best way of storing and accessing this schema?
- A physical .xsd file in the same location as the web service?
- A constant string in the code file of the web service?
- A string value in a resource file of the project?
- Somewhere in the web config?
- In a database?
I don't think options (2) and (3) would be the best since the schema might change and then we'll need to change the code. Then again, if the XML structure changes, we'll need to change the code anyway in order to parse the XML correctly.
Thanks!
原文:https://stackoverflow.com/questions/18598146
最满意答案
我只有一个hacky解决方案,我愿意接受如何改进它的建议。 但它的确有效。
诀窍是在实际选择之后有一个不可见的项目被选中。 这样,当您重新选择所选项时,将再次调用
onNavigationItemSelected
。public class ReselectAdapter extends ArrayAdapter<String> { private Context mContext; private ArrayList<String> mItems; private int mInternalPosition; public ReselectAdapter(Context context, ArrayList<String> items) { super(context, R.layout.sherlock_spinner_item, items); mContext = context; mItems = items; } @Override public View getView(int position, View convertView, ViewGroup parent) { TextView textView = (TextView) convertView; if (textView == null) { textView = (TextView) LayoutInflater.from(mContext).inflate( R.layout.sherlock_spinner_item, null); textView.setText(mItems.get(mInternalPosition)); } return textView; } @Override public View getDropDownView(int position, View convertView, ViewGroup parent) { TextView textView = null; if (position == mItems.size() - 1) { textView = new TextView(mContext); textView.setHeight(0); } else { textView = (TextView) LayoutInflater.from(mContext) .inflate(R.layout.sherlock_spinner_dropdown_item, parent, false); textView.setText(mItems.get(position)); } parent.setVerticalScrollBarEnabled(false); return textView; } public void setInternalPosition(int internalPosition) { mInternalPosition = internalPosition; } }
@Override public void onCreate(Bundle savedInstanceState) { // [...] ArrayList<String> items = new ArrayList<String>(); items.add("A"); items.add("B"); items.add("C"); items.add(""); // the last item is the invisible one mReselectAdapter = new ReselectAdapter(context, items); getSupportActionBar().setListNavigationCallbacks(mReselectAdapter, this); }
@Override public boolean onNavigationItemSelected(int itemPosition, long itemId) { int navigationItemCount = getSupportActionBar().getNavigationItemCount(); if (itemPosition == navigationItemCount - 1) { return true; } Log.i("onNavigationItemSelected", mReselectAdapter.getItem(itemPosition)); mReselectAdapter.setInternalPosition(itemPosition); getSupportActionBar().setSelectedNavigationItem(navigationItemCount - 1); return true; }
I only have a hacky solution to this and I am open for suggestions how to improve it. But it works.
The trick is to have an invisible item that gets selected after the actual selection. This way,
onNavigationItemSelected
gets called again when you reselect the selected item.public class ReselectAdapter extends ArrayAdapter<String> { private Context mContext; private ArrayList<String> mItems; private int mInternalPosition; public ReselectAdapter(Context context, ArrayList<String> items) { super(context, R.layout.sherlock_spinner_item, items); mContext = context; mItems = items; } @Override public View getView(int position, View convertView, ViewGroup parent) { TextView textView = (TextView) convertView; if (textView == null) { textView = (TextView) LayoutInflater.from(mContext).inflate( R.layout.sherlock_spinner_item, null); textView.setText(mItems.get(mInternalPosition)); } return textView; } @Override public View getDropDownView(int position, View convertView, ViewGroup parent) { TextView textView = null; if (position == mItems.size() - 1) { textView = new TextView(mContext); textView.setHeight(0); } else { textView = (TextView) LayoutInflater.from(mContext) .inflate(R.layout.sherlock_spinner_dropdown_item, parent, false); textView.setText(mItems.get(position)); } parent.setVerticalScrollBarEnabled(false); return textView; } public void setInternalPosition(int internalPosition) { mInternalPosition = internalPosition; } }
@Override public void onCreate(Bundle savedInstanceState) { // [...] ArrayList<String> items = new ArrayList<String>(); items.add("A"); items.add("B"); items.add("C"); items.add(""); // the last item is the invisible one mReselectAdapter = new ReselectAdapter(context, items); getSupportActionBar().setListNavigationCallbacks(mReselectAdapter, this); }
@Override public boolean onNavigationItemSelected(int itemPosition, long itemId) { int navigationItemCount = getSupportActionBar().getNavigationItemCount(); if (itemPosition == navigationItemCount - 1) { return true; } Log.i("onNavigationItemSelected", mReselectAdapter.getItem(itemPosition)); mReselectAdapter.setInternalPosition(itemPosition); getSupportActionBar().setSelectedNavigationItem(navigationItemCount - 1); return true; }
相关问答
更多-
我认为通过“后退”按钮,您的意思是用于向上导航应用程序结构层次结构的按钮。 无论如何,如果您不想将应用程序图标保持在最顶层,请希望这段代码能够解决您的问题。 ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayUseLogoEnabled(false); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowTitleEnabled(true) ...
-
ActionBarSherlock与ActionBar兼容性之间的区别(Difference between ActionBarSherlock and ActionBar Compatibility)[2023-06-24]
ActionBarSherlock为您的应用程序提供了一个操作栏,无论您的应用程序正在运行什么版本的Android API。 只有当您运行的设备是API 3.0级或更高版本时,操作栏兼容性才能为您提供操作栏。 *请注意,如果您运行的设备不是3.0或更高版本,ActionBarSherlock将使用它自己的自定义实现的操作栏,而不是本机的。 - 编辑 - 看来事情已经改变,ActionBarSherlock和Action Bar兼容性之间实际上没有区别。 请阅读下面的意见以了解详情。 - 编辑 - 现在使用两 ... -
ActionBarSherlock:显示并隐藏ActionBar + StatusBar(ActionBarSherlock: Show and Hide the ActionBar + StatusBar)[2022-03-21]
自答案: 我不得不删除模板中自动生成的这些行: if ((mFlags & FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES) == 0) { mActivity.getWindow().setFlags( WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_LAYOUT ... -
事实证明, RelativeLayout必须设置android:layout_gravity="top"才能使layout_marginTop工作。 It turns out the RelativeLayout must set android:layout_gravity="top" to make layout_marginTop work.
-
这似乎是一个问题,并且有一些解决方案。 我尝试了其中一些并取得了成功 - 看看这个问题 。 It seems that it is a issue and there are a few solutions. I tried some of them and succeeded - take a look at this issue.
-
ActionBarSherlock和ActionBar.OnNavigationListener(ActionBarSherlock and ActionBar.OnNavigationListener)[2023-09-06]
我只有一个hacky解决方案,我愿意接受如何改进它的建议。 但它的确有效。 诀窍是在实际选择之后有一个不可见的项目被选中。 这样,当您重新选择所选项时,将再次调用onNavigationItemSelected 。 public class ReselectAdapter extends ArrayAdapter{ private Context mContext; private ArrayList mItems; private int mInt ... -
好吧,显然,在我的设置中,你无法使用主题来做到这一点。 我最终做到了这一点,像这样全球化。 setTheme(theme.whatever); requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); super.onCreate(savedInstanceState); setContentView(R.layout.content); getSupportActionBar().setBackgroundDrawable(getResources( ...
-
步骤1:将ActionBarSherlock JAR添加到项目的libs/目录中。 步骤2:让您的活动(或整个应用程序)使用Sherlock风格的主题(例如, Theme.Sherlock , Theme.Sherlock.Light ) 步骤#3:将所有活动更改为继承自Sherlock风格的等效项(例如, Activity - > SherlockActivity , ListActivity - > SherlockListActivity ) 步骤#4:将所有片段更改为继承自Sherlock风格的等效 ...
-
使用标签的自定义视图 ActionBar.Tab tab = getSupportActionBar().newTab(); tab.setCustomView(R.layout.custom_tab_view); 然后,您可以获得自定义布局的视图并进行闪烁 This is How I solved my problem, Hope it can be useful for someone else too.... First I created a CutomImageView by exten ...
-
Actionbarsherlock中的标签总是在操作栏内?(Tabs in Actionbarsherlock are always inside the actionbar?)[2023-04-13]
根据操作栏选项卡指南 : 系统根据不同的屏幕尺寸调整操作栏选项卡 - 当屏幕足够宽时将它们放置在主操作栏中,或者当屏幕太窄时将其放置在单独的栏(称为“堆叠操作栏”)中 由于ActionBarSherlock模仿平台行为,如果有足够的空间,选项卡将显示在操作栏中。 您无法按其他 答案强制堆叠操作栏模式。 Per the Action Bar Tabs guide: the system adapts the action bar tabs for different screen sizes—placing ...