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


Java StartElement.getNamespaces方法代码示例

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


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

示例1: handleStartElement

import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
private void handleStartElement(StartElement event) throws SAXException {
    // start namespace bindings
    for (Iterator i = event.getNamespaces(); i.hasNext();) {
        Namespace ns = (Namespace)i.next();
        visitor.startPrefixMapping(
            fixNull(ns.getPrefix()),
            fixNull(ns.getNamespaceURI()));
    }

    // fire startElement
    QName qName = event.getName();
    tagName.uri = fixNull(qName.getNamespaceURI());
    String localName = qName.getLocalPart();
    tagName.uri = fixNull(qName.getNamespaceURI());
    tagName.local = localName;
    tagName.atts = getAttributes(event);
    visitor.startElement(tagName);

    seenText = false;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:StAXEventConnector.java

示例2: handleStartElement

import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
private void handleStartElement(StartElement startElement) throws SAXException {
	if (getContentHandler() != null) {
		QName qName = startElement.getName();
		if (hasNamespacesFeature()) {
			for (Iterator i = startElement.getNamespaces(); i.hasNext();) {
				Namespace namespace = (Namespace) i.next();
				startPrefixMapping(namespace.getPrefix(), namespace.getNamespaceURI());
			}
			for (Iterator i = startElement.getAttributes(); i.hasNext();){
				Attribute attribute = (Attribute) i.next();
				QName attributeName = attribute.getName();
				startPrefixMapping(attributeName.getPrefix(), attributeName.getNamespaceURI());
			}

			getContentHandler().startElement(qName.getNamespaceURI(), qName.getLocalPart(), toQualifiedName(qName),
					getAttributes(startElement));
		}
		else {
			getContentHandler().startElement("", "", toQualifiedName(qName), getAttributes(startElement));
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:StaxEventXMLReader.java

示例3: withNamespace

import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
private StartElement withNamespace(StartElement startElement) {
	// otherwise, wrap the start element event to provide a default namespace mapping
	final List<Namespace> namespaces = new ArrayList<Namespace>();
	namespaces.add( xmlEventFactory.createNamespace( "", namespaceUri ) );
	Iterator<?> originalNamespaces = startElement.getNamespaces();
	while ( originalNamespaces.hasNext() ) {
		namespaces.add( (Namespace) originalNamespaces.next() );
	}
	return xmlEventFactory.createStartElement(
			new QName( namespaceUri, startElement.getName().getLocalPart() ),
			startElement.getAttributes(),
			namespaces.iterator()
	);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:JaxbProcessor.java

示例4: testEventReader

import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
@Test
public void testEventReader() {
    try {
        XMLInputFactory ifac = XMLInputFactory.newInstance();
        XMLEventReader read = ifac.createXMLEventReader(this.getClass().getResource(INPUT_FILE).toExternalForm(),
                this.getClass().getResourceAsStream(INPUT_FILE));
        while (read.hasNext()) {
            XMLEvent event = read.nextEvent();
            if (event.isStartElement()) {
                StartElement startElement = event.asStartElement();
                if (startElement.getName().getLocalPart().equals("bookurn")) {
                    Iterator iterator = startElement.getNamespaces();
                    int count = 0;
                    while (iterator.hasNext()) {
                        iterator.next();
                        count++;
                    }
                    Assert.assertTrue(count == 2, "Two namespaces are expected for <bookurn> ");

                    Iterator attributes = startElement.getAttributes();
                    count = 0;
                    while (attributes.hasNext()) {
                        iterator.next();
                        count++;
                    }
                    Assert.assertTrue(count == 0, "Zero attributes are expected for <bookurn> ");
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Exception occured: " + e.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:DefaultAttributeTest.java

示例5: toField

import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
Map<String, Field> toField(StartElement startE) {
  Map<String, Field> map = new LinkedHashMap<>();
  Iterator attrs = startE.getAttributes();
  while (attrs.hasNext()) {
    Attribute attr = (Attribute) attrs.next();
    map.put(getName(ATTR_PREFIX_KEY, attr), Field.create(attr.getValue()));
  }
  Iterator nss = startE.getNamespaces();
  while (nss.hasNext()) {
    Namespace ns = (Namespace) nss.next();
    map.put(getName(NS_PREFIX_KEY, ns), Field.create(ns.getNamespaceURI()));
  }
  return map;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:15,代码来源:StreamingXmlParser.java

示例6: add

import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
public void add(XMLEvent event) throws XMLStreamException {
	if (event.isStartDocument()) {
		streamWriter.writeStartDocument();
	} else if (event.isStartElement()) {
		StartElement element = event.asStartElement();
		QName elQName = element.getName();
		if (elQName.getPrefix().length() > 0
				&& elQName.getNamespaceURI().length() > 0)
			streamWriter.writeStartElement(elQName.getPrefix(), elQName
					.getLocalPart(), elQName.getNamespaceURI());
		else if (elQName.getNamespaceURI().length() > 0)
			streamWriter.writeStartElement(elQName.getNamespaceURI(),
					elQName.getLocalPart());
		else
			streamWriter.writeStartElement(elQName.getLocalPart());

		// Add element namespaces
		Iterator namespaces = element.getNamespaces();
		while (namespaces.hasNext()) {
			Namespace ns = (Namespace) namespaces.next();
			String prefix = ns.getPrefix();
			String nsURI = ns.getNamespaceURI();
			streamWriter.writeNamespace(prefix, nsURI);
		}

		// Add element attributes
		Iterator attris = element.getAttributes();
		while (attris.hasNext()) {
			Attribute attr = (Attribute) attris.next();
			QName atQName = attr.getName();
			String value = attr.getValue();
			if (atQName.getPrefix().length() > 0
					&& atQName.getNamespaceURI().length() > 0)
				streamWriter.writeAttribute(atQName.getPrefix(), atQName
						.getNamespaceURI(), atQName.getLocalPart(), value);
			else if (atQName.getNamespaceURI().length() > 0)
				streamWriter.writeAttribute(atQName.getNamespaceURI(),
						atQName.getLocalPart(), value);
			else
				streamWriter.writeAttribute(atQName.getLocalPart(), value);
		}
	} else if (event.isCharacters()) {
		Characters chars = event.asCharacters();
		streamWriter.writeCharacters(chars.getData());
	} else if (event.isEndElement()) {
		streamWriter.writeEndElement();
	} else if (event.isEndDocument()) {
		streamWriter.writeEndDocument();
	} else {
		throw new XMLStreamException("Unsupported event type: " + event);
	}
}
 
开发者ID:jettison-json,项目名称:jettison,代码行数:53,代码来源:AbstractXMLEventWriter.java

示例7: readXml

import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
XmlElement readXml() {
  XmlElement root = null;
  try {
    XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
    XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(reader);
    while (xmlEventReader.hasNext()) {
      XMLEvent xmlEvent = xmlEventReader.nextEvent();
      
      /*if (xmlEvent.isStartDocument()){
        StartDocument startDocument = (StartDocument) xmlEvent;
      } else */
      
      XmlElement parent = !elementStack.isEmpty() ? elementStack.peek() : null;
      if (xmlEvent.isStartElement()){
        StartElement startElement = (StartElement)xmlEvent;
        
        // create the xml element
        XmlElement xmlElement = new XmlElement();
        if (parent==null) {
          root = xmlElement;
        } else {
          // establish parent-child relation
          parent.addElement(xmlElement);
          xmlElement.parent = parent;
        }

        // initialize namespaces
        Iterator namespaces = startElement.getNamespaces();
        while (namespaces.hasNext()) {
          Namespace namespace = (Namespace) namespaces.next();
          xmlElement.addNamespace(namespace.getNamespaceURI(), namespace.getPrefix());
        }

        // set the name (depends on the namespaces being initialized)
        QName qname = startElement.getName();
        xmlElement.setName(qname.getNamespaceURI(), qname.getLocalPart());
        
        // set the attributes (depends on the namespaces being initialized)
        Iterator attributes = startElement.getAttributes();
        while (attributes.hasNext()) {
          Attribute attribute = (Attribute) attributes.next();
          QName attributeQname = attribute.getName();
          xmlElement.addAttribute(attributeQname.getNamespaceURI(), attributeQname.getLocalPart(), attribute.getValue());
        }

        elementStack.push(xmlElement);
      } else if (xmlEvent.isEndElement()){
        elementStack.pop();
      } else if (xmlEvent.isCharacters()){
        parent.addText(xmlEvent.asCharacters().getData()); 
      }
    }
  } catch (XMLStreamException e) {
    throw new XmlParsingError(e);
  }
  return root;
}
 
开发者ID:effektif,项目名称:effektif,代码行数:58,代码来源:XmlReader.java


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