当前位置: 首页>>代码示例>>Java>>正文


Java AbstractXMLStreamWriter.writeStartElement方法代码示例

本文整理汇总了Java中org.codehaus.jettison.AbstractXMLStreamWriter.writeStartElement方法的典型用法代码示例。如果您正苦于以下问题:Java AbstractXMLStreamWriter.writeStartElement方法的具体用法?Java AbstractXMLStreamWriter.writeStartElement怎么用?Java AbstractXMLStreamWriter.writeStartElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.codehaus.jettison.AbstractXMLStreamWriter的用法示例。


在下文中一共展示了AbstractXMLStreamWriter.writeStartElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testAttributeKey

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testAttributeKey() throws Exception {
    StringWriter strWriter = new StringWriter();
    
    Map xtoj = new HashMap();
    xtoj.put("http://foo/", "foo");
    Configuration conf = new Configuration(xtoj);
    conf.setAttributeKey("!");
    MappedNamespaceConvention con = new MappedNamespaceConvention(conf);
    AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
    
    w.writeStartDocument();
    w.writeStartElement("root");
    w.writeAttribute("att", "attvalue");
    w.writeAttribute("http://foo/", "att2", "attvalue");
    
    w.writeEndElement();
    w.writeEndDocument();
    
    w.close();
    strWriter.close();
    
    assertEquals("{\"root\":{\"!att\":\"attvalue\",\"!foo.att2\":\"attvalue\"}}", strWriter.toString());
}
 
开发者ID:jettison-json,项目名称:jettison,代码行数:24,代码来源:MappedXMLStreamWriterTest.java

示例2: testChild

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testChild() throws Exception {
    StringWriter strWriter = new StringWriter();
    MappedNamespaceConvention con = new MappedNamespaceConvention();
    AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
    
    w.writeStartDocument();
    w.writeStartElement("root");
    w.writeStartElement("child");
    w.writeEndElement();
    w.writeEndElement();
    w.writeEndDocument();
    
    w.close();
    strWriter.close();
    
    assertEquals("{\"root\":{\"child\":\"\"}}", strWriter.toString());
}
 
开发者ID:jettison-json,项目名称:jettison,代码行数:18,代码来源:MappedXMLStreamWriterTest.java

示例3: testChildDropElement3

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testChildDropElement3() throws Exception {
    StringWriter strWriter = new StringWriter();
    Configuration c = new Configuration();
    List<String> ignoredElements = new LinkedList<String>();
    ignoredElements.add("root");
    ignoredElements.add("root2");
    c.setIgnoredElements(ignoredElements);
    MappedNamespaceConvention con = new MappedNamespaceConvention(c);
    AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
    
    w.writeStartDocument();
    w.writeStartElement("root");
    w.writeStartElement("root2");
    w.writeStartElement("child");
    w.writeEndElement();
    w.writeEndElement();
    w.writeEndElement();
    w.writeEndDocument();
    
    w.close();
    strWriter.close();
    
    assertEquals("{\"child\":\"\"}", strWriter.toString());
}
 
开发者ID:jettison-json,项目名称:jettison,代码行数:25,代码来源:MappedXMLStreamWriterTest.java

示例4: testSingleArrayElement

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testSingleArrayElement() throws Exception {
	StringWriter strWriter = new StringWriter();
	MappedNamespaceConvention con = new MappedNamespaceConvention();
	AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
	w.serializeAsArray(con.createKey("", "", "array-a"));

	w.writeStartDocument();
	w.writeStartElement("", "array-a", "");

	w.writeStartElement("", "a", "");
	w.writeStartElement("", "n", "");
	w.writeCharacters("1");
	w.writeEndElement();
	w.writeEndElement();

	w.writeEndElement();
	w.writeEndDocument();

	w.close();
	strWriter.close();

	assertEquals("{\"array-a\":[{\"a\":{\"n\":1}}]}", strWriter.toString());
}
 
开发者ID:jettison-json,项目名称:jettison,代码行数:24,代码来源:MappedXMLStreamWriterTest.java

示例5: x_testImplicitCollections

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void x_testImplicitCollections() throws Exception {
    StringWriter strWriter = new StringWriter();
    Configuration conf = new Configuration();
    MappedNamespaceConvention con = new MappedNamespaceConvention(conf);
    AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
    
    w.writeStartDocument();
    w.writeStartElement("root");
    
    addChild(w);
    addChild(w);
    addChild(w);
    addChild(w);
    
    w.writeEndElement();
    w.writeEndDocument();
    
    w.close();
    strWriter.close();
    
    assertEquals("{\"root\":[" +
                 "{\"subchild1\":\"test\",\"subchild2\":\"test\"}," +
                 "{\"subchild1\":\"test\",\"subchild2\":\"test\"}," +
                 "{\"subchild1\":\"test\",\"subchild2\":\"test\"}," +
                 "{\"subchild1\":\"test\",\"subchild2\":\"test\"}]}", strWriter.toString());
}
 
开发者ID:jettison-json,项目名称:jettison,代码行数:27,代码来源:MappedXMLStreamWriterTest.java

示例6: testComplexElements

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testComplexElements() throws Exception {
    StringWriter strWriter = new StringWriter();
    MappedNamespaceConvention con = new MappedNamespaceConvention();
    AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
    
    w.writeStartDocument();
    w.writeStartElement("", "a", "");

    w.writeStartElement("", "o", "");
    w.writeAttribute("class", "string");
    w.writeCharacters("1");
    w.writeEndElement();
    
    w.writeEndElement();
    w.writeEndDocument();
    
    w.close();
    strWriter.close();
    
    assertEquals("{\"a\":{\"o\":{\"@class\":\"string\",\"$\":\"1\"}}}", strWriter.toString());
}
 
开发者ID:jettison-json,项目名称:jettison,代码行数:22,代码来源:MappedXMLStreamWriterTest.java

示例7: testTextForwardSlashFirstChar

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testTextForwardSlashFirstChar() throws Exception {
    StringWriter strWriter = new StringWriter();
    MappedNamespaceConvention con = new MappedNamespaceConvention();
    AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
    
    w.writeStartDocument();
    w.writeStartElement("root");
    w.writeStartElement("child");
    
    w.writeCharacters("/abc");
    w.writeEndElement();
    w.writeEndElement();
    w.writeEndDocument();
    
    w.close();
    strWriter.close();
    
    assertEquals("{\"root\":{\"child\":\"/abc\"}}", strWriter.toString());
}
 
开发者ID:jettison-json,项目名称:jettison,代码行数:20,代码来源:MappedXMLStreamWriterTest.java

示例8: testEmptySerializedArrayElement

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testEmptySerializedArrayElement() throws Exception {
    StringWriter strWriter = new StringWriter();
    MappedNamespaceConvention con = new MappedNamespaceConvention();
    AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
    w.serializeAsArray(con.createKey("", "", "array-a"));

    w.writeStartDocument();
    w.writeStartElement("", "array-a", "");

    w.writeEndElement();
    w.writeEndDocument();

    w.close();
    strWriter.close();

    assertEquals("{\"array-a\":[\"\"]}", strWriter.toString());
}
 
开发者ID:jettison-json,项目名称:jettison,代码行数:18,代码来源:MappedXMLStreamWriterTest.java

示例9: testSingleArrayElementIgnore

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testSingleArrayElementIgnore() throws Exception {
	StringWriter strWriter = new StringWriter();
	MappedNamespaceConvention con = new MappedNamespaceConvention();
	AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);

	w.writeStartDocument();
	w.writeStartElement("", "array-a", "");

	w.writeStartElement("", "a", "");
	w.writeStartElement("", "n", "");
	w.writeCharacters("1");
	w.writeEndElement();
	w.writeEndElement();

	w.writeEndElement();
	w.writeEndDocument();

	w.close();
	strWriter.close();

	assertEquals("{\"array-a\":{\"a\":{\"n\":1}}}", strWriter.toString());
}
 
开发者ID:jettison-json,项目名称:jettison,代码行数:23,代码来源:MappedXMLStreamWriterTest.java

示例10: testIntAttributeAsString

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testIntAttributeAsString() throws Exception {
    StringWriter strWriter = new StringWriter();
    
    Configuration c = new Configuration();
    c.setTypeConverter(new SimpleConverter());
    MappedNamespaceConvention con = new MappedNamespaceConvention(c);
    AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
    
    w.writeStartDocument();
    w.writeStartElement("root");
    w.writeAttribute("att", "123");
    w.writeEndElement();
    w.writeEndDocument();
    
    w.close();
    strWriter.close();
    
    assertEquals("{\"root\":{\"@att\":\"123\"}}", strWriter.toString());
}
 
开发者ID:jettison-json,项目名称:jettison,代码行数:20,代码来源:MappedXMLStreamWriterTest.java

示例11: testNamespacedElements

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testNamespacedElements() throws Exception {
    StringWriter strWriter = new StringWriter();
    
    Map xtoj = new HashMap();
    xtoj.put("http://foo/", "foo");
    MappedNamespaceConvention con = new MappedNamespaceConvention(new Configuration(xtoj));
    
    AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
    
    w.writeStartDocument();
    w.writeStartElement("http://foo/", "root");
    
    w.writeStartElement("http://foo/", "child");
    w.writeEndElement();
    
    w.writeStartElement("http://foo/", "child");
    w.writeEndElement();
    
    w.writeEndElement();
    w.writeEndDocument();
    
    w.close();
    strWriter.close();
    
    assertEquals("{\"foo.root\":{\"foo.child\":[\"\",\"\"]}}", strWriter.toString());
}
 
开发者ID:jettison-json,项目名称:jettison,代码行数:27,代码来源:MappedXMLStreamWriterTest.java

示例12: testPrimitiveInfinityNaN

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testPrimitiveInfinityNaN() throws Exception {
    StringWriter strWriter = new StringWriter();
    MappedNamespaceConvention con = new MappedNamespaceConvention();
    AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);

    w.writeStartDocument();
    w.writeStartElement("root");


    w.writeStartElement("subchild1");
    w.writeCharacters("Infinity");
    w.writeEndElement();

    w.writeStartElement("subchild1");
    w.writeCharacters("NaN");
    w.writeEndElement();


    w.writeEndElement();
    w.writeEndDocument();

    w.close();
    strWriter.close();
    String expected = "{\"root\":{\"subchild1\":[\"Infinity\",\"NaN\"]}}";
    String actual = strWriter.toString();
    assertEquals(expected, actual);
}
 
开发者ID:jettison-json,项目名称:jettison,代码行数:28,代码来源:MappedXMLStreamWriterTest.java

示例13: testIssue18Enh

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testIssue18Enh() throws Exception {
    StringWriter strWriter = new StringWriter();
    MappedNamespaceConvention con = new MappedNamespaceConvention();
    AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
    
    w.writeStartDocument();
    w.writeStartElement("", "a", "");

    w.writeStartElement("", "vals", "");
    
    w.writeStartElement("", "string", "");
    w.writeCharacters("1");
    w.writeEndElement();
    
    w.writeStartElement("", "string", "");
    w.writeCharacters("2");
    w.writeEndElement();
    
    w.writeStartElement("", "string", "");
    w.writeCharacters("3");
    w.writeEndElement();
    
    w.writeEndElement();
    
    w.writeStartElement("", "n", "");
    w.writeCharacters("5");
    w.writeEndElement();
    
    w.writeEndElement();
    w.writeEndDocument();
    
    w.close();
    strWriter.close();

    assertEquals("{\"a\":{\"vals\":{\"string\":[1,2,3]},\"n\":5}}", strWriter.toString());
}
 
开发者ID:jettison-json,项目名称:jettison,代码行数:37,代码来源:MappedXMLStreamWriterTest.java

示例14: testTwoChildrenWithSubChildWithText

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testTwoChildrenWithSubChildWithText() throws Exception {
    StringWriter strWriter = new StringWriter();
    MappedNamespaceConvention con = new MappedNamespaceConvention();
    AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
    
    w.writeStartDocument();
    w.writeStartElement("root");
    
    w.writeStartElement("child1");
    w.writeStartElement("subchild1");
    w.writeCharacters("test");
    w.writeEndElement();
    
    w.writeStartElement("subchild2");
    w.writeCharacters("test");
    w.writeEndElement();
    
    w.writeEndElement();
    
    w.writeStartElement("child2");
    w.writeStartElement("subchild");
    w.writeCharacters("test");
    w.writeEndElement();
    w.writeEndElement();
    
    w.writeEndElement();
    w.writeEndDocument();
    
    w.close();
    strWriter.close();
    
    assertEquals("{\"root\":{" +
                    "\"child1\":{\"subchild1\":\"test\",\"subchild2\":\"test\"}," +
                    "\"child2\":{\"subchild\":\"test\"}}}", strWriter.toString());
}
 
开发者ID:jettison-json,项目名称:jettison,代码行数:36,代码来源:MappedXMLStreamWriterTest.java

示例15: testNestedSerializedArrayElement

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testNestedSerializedArrayElement() throws Exception {
    StringWriter strWriter = new StringWriter();
    MappedNamespaceConvention con = new MappedNamespaceConvention();
    AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
    w.serializeAsArray(con.createKey("", "", "docs"));
    w.serializeAsArray(con.createKey("", "", "filters"));
    w.serializeAsArray(con.createKey("", "", "hosts"));

    w.writeStartDocument();
    w.writeStartElement("", "docs", "");
    w.writeStartElement("", "doc", "");
    
    w.writeStartElement("", "id", "");
    w.writeCharacters("24");
    w.writeEndElement();
    
    w.writeStartElement("", "filters", "");
    w.writeEndElement();
    
    w.writeStartElement("", "hosts", "");
    w.writeStartElement("", "host", "");
    w.writeStartElement("", "name", "");
    w.writeCharacters("foobar.com");
    w.writeEndElement(); //name
    w.writeStartElement("", "ip", "");
    w.writeCharacters("255.255.255.255");
    w.writeEndElement(); //ip
    w.writeEndElement(); // host
    w.writeEndElement(); //hosts

    w.writeEndElement(); // doc
    w.writeEndElement(); // docs
    w.writeEndDocument();

    w.close();
    strWriter.close();

    assertEquals("{\"docs\":[{\"doc\":{\"id\":24,\"filters\":[\"\"],\"hosts\":[{\"host\":{\"name\":\"foobar.com\",\"ip\":\"255.255.255.255\"}}]}}]}", strWriter.toString());
}
 
开发者ID:jettison-json,项目名称:jettison,代码行数:40,代码来源:MappedXMLStreamWriterTest.java


注:本文中的org.codehaus.jettison.AbstractXMLStreamWriter.writeStartElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。