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


Java AbstractXMLStreamWriter.writeAttribute方法代码示例

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


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

示例1: testAttributes

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testAttributes() 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("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,代码行数:23,代码来源:MappedXMLStreamWriterTest.java

示例2: testIntAttribute

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testIntAttribute() throws Exception {
    StringWriter strWriter = new StringWriter();
    
    MappedNamespaceConvention con = new MappedNamespaceConvention(new Configuration());
    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,代码行数:18,代码来源:MappedXMLStreamWriterTest.java

示例3: 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

示例4: testAttributesAsElements

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testAttributesAsElements() throws Exception {
    StringWriter strWriter = new StringWriter();
    
    Map xtoj = new HashMap();
    xtoj.put("http://foo/", "foo");
    List atts = new ArrayList();
    atts.add(new QName("http://foo/", "att2"));
    
    Configuration c = new Configuration(xtoj, atts, null);
    
    MappedNamespaceConvention con = new MappedNamespaceConvention(c);
    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,代码行数:27,代码来源:MappedXMLStreamWriterTest.java

示例5: 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

示例6: 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

示例7: testAttributeAndText

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testAttributeAndText() throws Exception {
    StringWriter strWriter = new StringWriter();
    AbstractXMLStreamWriter w = new BadgerFishXMLStreamWriter(strWriter);
    
    w.writeStartDocument();
    w.writeStartElement("alice");
    
    w.writeAttribute("charlie", "david");
    w.writeCharacters("bob");
    
    w.writeEndElement();
    w.writeEndDocument();
    
    w.close();
    strWriter.close();
    
    assertJSONEquals("{\"alice\":{\"@charlie\":\"david\",\"$\":\"bob\"}}", 
                     strWriter.toString());
}
 
开发者ID:jettison-json,项目名称:jettison,代码行数:20,代码来源:BadgerFishXMLStreamWriterTest.java

示例8: testAttributesWithAtSupressed

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testAttributesWithAtSupressed() throws Exception {
    StringWriter strWriter = new StringWriter();
    
    Map xtoj = new HashMap();
    xtoj.put("http://foo/", "foo");
    List atts = new ArrayList();
    atts.add(new QName("http://foo/", "att2"));
    
    Configuration c = new Configuration(xtoj, atts, null);
    c.setSupressAtAttributes(true);
    
    MappedNamespaceConvention con = new MappedNamespaceConvention(c);
    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,代码行数:28,代码来源:MappedXMLStreamWriterTest.java

示例9: testArraysAndAttributes

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testArraysAndAttributes() 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.writeAttribute("x", "y");
    w.writeCharacters("value");
    w.writeEndElement();
    
    w.writeStartElement("child");
    w.writeAttribute("a", "b");
    w.writeCharacters("value");
    w.writeEndElement();
    
    w.writeStartElement("child");
    w.writeAttribute("x", "z");
    w.writeCharacters("value");
    w.writeEndElement();        
    
    w.writeEndElement();
    w.writeEndDocument();
    
    w.close();
    strWriter.close();
    
    assertEquals("{\"root\":{\"child\":[{\"@x\":\"y\",\"$\":\"value\"},{\"@a\":\"b\",\"$\":\"value\"},{\"@x\":\"z\",\"$\":\"value\"}]}}", strWriter.toString());
}
 
开发者ID:jettison-json,项目名称:jettison,代码行数:32,代码来源:MappedXMLStreamWriterTest.java

示例10: testMultipleChildrenAgain

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testMultipleChildrenAgain() throws Exception {
    StringWriter strWriter = new StringWriter();
    AbstractXMLStreamWriter xsw = new BadgerFishXMLStreamWriter(strWriter);
    
    xsw.writeStartDocument();
    xsw.writeStartElement("Ratings");

    xsw.writeStartElement("Rating");
    xsw.writeAttribute("id", "100");
    xsw.writeAttribute("value", "3");
    xsw.writeEndElement();

    xsw.writeStartElement("Rating");
    xsw.writeAttribute("id", "200");
    xsw.writeAttribute("value", "4");
    xsw.writeEndElement();

    xsw.writeStartElement("Rating");
    xsw.writeAttribute("id", "300");
    xsw.writeAttribute("value", "5");
    xsw.writeEndElement();

    xsw.writeEndElement();
    xsw.writeEndDocument ();
    xsw.flush();

    xsw.close();
    strWriter.close();
    System.out.println(strWriter.toString());
    
    assertJSONEquals("{\"Ratings\":{\"Rating\":[" +
                    "{\"@id\":\"100\",\"@value\":\"3\"}," +
                    "{\"@id\":\"200\",\"@value\":\"4\"}," +
                    "{\"@id\":\"300\",\"@value\":\"5\"}" +
                    "]}}", 
                     strWriter.toString());
}
 
开发者ID:jettison-json,项目名称:jettison,代码行数:38,代码来源:BadgerFishXMLStreamWriterTest.java

示例11: testChildClassPropertyNameSameAsParentObject

import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testChildClassPropertyNameSameAsParentObject() 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("definition");
                w.writeStartElement("structure");
                    w.writeAttribute("name", "conversation");
                    w.writeStartElement("symbolic");
                        w.writeAttribute("name", "reason");
                    w.writeEndElement();
                    w.writeStartElement("symbolic");
                        w.writeAttribute("name", "terms");
                    w.writeEndElement();
                    w.writeStartElement("numeric");
                        w.writeAttribute("name", "amountasked");
                    w.writeEndElement();
                    w.writeStartElement("numeric");
                        w.writeAttribute("name", "amountoffered");
                    w.writeEndElement();
                    w.writeStartElement("structure");
                        w.writeAttribute("name", "check");
                        w.writeStartElement("symbolic");
                            w.writeAttribute("name", "date");
                        w.writeEndElement();
                        w.writeStartElement("structure");
                            w.writeAttribute("name", "lines");
                            w.writeAttribute("repeating", "true");
                            w.writeStartElement("symbolic");
                                w.writeAttribute("name", "type");
                            w.writeEndElement();
                            w.writeStartElement("numeric");
                                w.writeAttribute("name", "amount");
                            w.writeEndElement();
                            w.writeStartElement("numeric");
                                w.writeAttribute("name", "cost");
                            w.writeEndElement();
                        w.writeEndElement();
                    w.writeEndElement();
                w.writeEndElement();
            w.writeEndElement();
        w.writeEndDocument();

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

        assertEquals("{\"definition\":" +
                "{\"structure\":{\"@name\":\"conversation\",\"symbolic\":" +
                "[{\"@name\":\"reason\"},{\"@name\":\"terms\"}],\"numeric\":[" +
                "{\"@name\":\"amountasked\"},{\"@name\":\"amountoffered\"}]," +
                "\"structure\":{\"@name\":\"check\",\"symbolic\":" +
                "{\"@name\":\"date\"},\"structure\":{\"@name\":\"lines\",\"@repeating\":true,\"symbolic\"" +
                ":{\"@name\":\"type\"},\"numeric\":[{\"@name\":\"amount\"},{\"@name\":\"cost\"}]}}}}}"
                , strWriter.toString());
    }
 
开发者ID:jettison-json,项目名称:jettison,代码行数:59,代码来源:MappedXMLStreamWriterTest.java


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