我有以下代码:
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlFile);
Run Code Online (Sandbox Code Playgroud)
我怎样才能解析String中包含的XML而不是文件?
给定以下代码,如何迭代ProfileCollection类型的对象?
public class ProfileCollection implements Iterable {
private ArrayList<Profile> m_Profiles;
public Iterator<Profile> iterator() {
Iterator<Profile> iprof = m_Profiles.iterator();
return iprof;
}
...
public Profile GetActiveProfile() {
return (Profile)m_Profiles.get(m_ActiveProfile);
}
}
public static void main(String[] args) {
m_PC = new ProfileCollection("profiles.xml");
// properly outputs a profile:
System.out.println(m_PC.GetActiveProfile());
// not actually outputting any profiles:
for(Iterator i = m_PC.iterator();i.hasNext();) {
System.out.println(i.next());
}
// how I actually want this to work, but won't even compile:
for(Profile prof: m_PC) {
System.out.println(prof);
}
}
Run Code Online (Sandbox Code Playgroud) 如何在rails 4.x中禁用查询缓存?似乎将我的查询包装在model.uncached {}中并不会停止查询缓存.还有其他设置吗?
使用SWT,指示菜单项(来自任务栏菜单)是当前活动选择的常用方法是什么?复选标记?胆大?如何用代码完成?
当你注意到一个应用程序有很多类,但是这些类不是真正的可对等对象而是一组常用函数时,你会怎么做?
例:
Class Point
{
calculatePoints(something) {}
calculatePointsAnotherWay(something) {}
}
Run Code Online (Sandbox Code Playgroud) 如果我有一个有苹果的树,我应该如何模拟苹果树所拥有的这个事实.考虑将有3个数据库表:tree,apple,tree_apples.
在我看来,会有一个AppleDecorator类,以便Tree可以拥有多个AppleDecorator,并为每个将这个关联写入tree_apples的函数调用 - > save().Apple不知道它归Tree所有.
除了获取所有树的ID之外,从Tree类引用tree_apples表似乎是错误的,因为Tree类为它拥有的每种类型的对象引用一个表(并且需要存储它有一个的事实) ).即使获得ID也可以卸载到Iterator之类的东西.
应用程序需要存储一个对象拥有N个其他对象的事实应该如何?(在这种情况下,我的类需要存储5种其他类型对象的关联).