本文整理匯總了Java中javax.xml.stream.XMLEventFactory.setLocation方法的典型用法代碼示例。如果您正苦於以下問題:Java XMLEventFactory.setLocation方法的具體用法?Java XMLEventFactory.setLocation怎麽用?Java XMLEventFactory.setLocation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.stream.XMLEventFactory
的用法示例。
在下文中一共展示了XMLEventFactory.setLocation方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testSetLocation
import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
@Test
public void testSetLocation() {
XMLEventFactory factory = XMLEventFactory.newInstance();
Location loc = new MyLocation();
factory.setLocation(loc);
XMLEvent event = factory.createComment("some comment");
Assert.assertEquals(event.getLocation().getLineNumber(), 15);
}
示例2: assignIdToElement
import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
protected StartElement assignIdToElement(StartElement element)
{
List<Attribute> attrs = new ArrayList<Attribute>();
Attribute idAttr = null;
for (Iterator<Attribute> i = element.getAttributes(); i.hasNext();)
{
Attribute attr = i.next();
if (ID_ATTR_QNAME.equals(attr.getName()))
idAttr = attr;
attrs.add(attr);
}
if (null == idAttr)
{
String id = Integer.toString(++lastId);
int len = id.length();
if (6 < len)
throw new IndexOutOfBoundsException("Too many TOC entries: " + id + ", cannot allocate an id");
id = idBuf.replace(9 - len, 9, id).toString();
XMLEventFactory eventFactory = getXMLEventFactory();
idAttr = eventFactory.createAttribute(ID_ATTR_QNAME, id);
attrs.add(idAttr);
eventFactory.setLocation(element.getLocation());
element = eventFactory.createStartElement(
element.getName(),
attrs.iterator(),
element.getNamespaces());
eventFactory.setLocation(null);
}
return element;
}
示例3: get
import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
public XMLEventFactory get() {
XMLEventFactory eventFactory = super.get();
eventFactory.setLocation(null);
return eventFactory;
}