本文整理汇总了Java中javax.xml.namespace.NamespaceContext类的典型用法代码示例。如果您正苦于以下问题:Java NamespaceContext类的具体用法?Java NamespaceContext怎么用?Java NamespaceContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NamespaceContext类属于javax.xml.namespace包,在下文中一共展示了NamespaceContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: switchToXML11Scanner
import javax.xml.namespace.NamespaceContext; //导入依赖的package包/类
private void switchToXML11Scanner() throws IOException {
int oldEntityDepth = fScanner.fEntityDepth;
com.sun.org.apache.xerces.internal.xni.NamespaceContext oldNamespaceContext
= fScanner.fNamespaceContext;
fScanner = new XML11NSDocumentScannerImpl();
//get the new scanner state to old scanner's previous state
fScanner.reset(fPropertyManager);
fScanner.setPropertyManager(fPropertyManager);
fEntityScanner = fEntityManager.getEntityScanner();
fEntityScanner.registerListener(fScanner);
fEntityManager.fCurrentEntity.mayReadChunks = true;
fScanner.setScannerState(XMLEvent.START_DOCUMENT);
fScanner.fEntityDepth = oldEntityDepth;
fScanner.fNamespaceContext = oldNamespaceContext;
fEventType = fScanner.next();
}
示例2: test
import javax.xml.namespace.NamespaceContext; //导入依赖的package包/类
@Test
public void test() {
try {
XMLOutputFactory xof = XMLOutputFactory.newInstance();
StreamResult sr = new StreamResult();
XMLStreamWriter xsw = xof.createXMLStreamWriter(sr);
NamespaceContext nc = xsw.getNamespaceContext();
System.out.println(nc.getPrefix(XMLConstants.XML_NS_URI));
System.out.println(" expected result: " + XMLConstants.XML_NS_PREFIX);
System.out.println(nc.getPrefix(XMLConstants.XMLNS_ATTRIBUTE_NS_URI));
System.out.println(" expected result: " + XMLConstants.XMLNS_ATTRIBUTE);
Assert.assertTrue(nc.getPrefix(XMLConstants.XML_NS_URI) == XMLConstants.XML_NS_PREFIX);
Assert.assertTrue(nc.getPrefix(XMLConstants.XMLNS_ATTRIBUTE_NS_URI) == XMLConstants.XMLNS_ATTRIBUTE);
} catch (Throwable ex) {
Assert.fail(ex.toString());
}
}
示例3: testNamespaceContext
import javax.xml.namespace.NamespaceContext; //导入依赖的package包/类
@Test
public void testNamespaceContext() {
try {
XMLInputFactory xif = XMLInputFactory.newInstance();
xif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
InputStream is = new java.io.ByteArrayInputStream(getXML().getBytes());
XMLStreamReader sr = xif.createXMLStreamReader(is);
while (sr.hasNext()) {
int eventType = sr.next();
if (eventType == XMLStreamConstants.START_ELEMENT) {
if (sr.getLocalName().equals(childElement)) {
NamespaceContext context = sr.getNamespaceContext();
Assert.assertTrue(context.getPrefix(namespaceURI).equals(prefix));
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例4: run
import javax.xml.namespace.NamespaceContext; //导入依赖的package包/类
public void run() {
NamespaceContext ns = nsc;
if(xsw!=null) ns = xsw.getNamespaceContext();
if(xew!=null) ns = xew.getNamespaceContext();
// StAX javadoc isn't very clear on the behavior,
// so work defensively in anticipation of broken implementations.
if(ns==null)
return;
// we can't enumerate all the in-scope namespace bindings in StAX,
// so we only look for the known static namespace URIs.
// this is less than ideal, but better than nothing.
for( String nsUri : serializer.grammar.nameList.namespaceURIs ) {
String p = ns.getPrefix(nsUri);
if(p!=null)
serializer.addInscopeBinding(nsUri,p);
}
}
示例5: startDocument
import javax.xml.namespace.NamespaceContext; //导入依赖的package包/类
@Override
public void startDocument(LocatorEx locator, NamespaceContext nsContext) throws SAXException {
if(locator!=null)
this.locator = locator;
this.environmentNamespaceContext = nsContext;
// reset the object
result = null;
current = root;
patchersLen=0;
aborted = false;
isUnmarshalInProgress = true;
nsLen=0;
if(expectedType!=null)
root.loader = EXPECTED_TYPE_ROOT_LOADER;
else
root.loader = DEFAULT_ROOT_LOADER;
idResolver.startDocument(this);
}
示例6: handleStartDocument
import javax.xml.namespace.NamespaceContext; //导入依赖的package包/类
protected final void handleStartDocument(NamespaceContext nsc) throws SAXException {
visitor.startDocument(new LocatorEx() {
public ValidationEventLocator getLocation() {
return new ValidationEventLocatorImpl(this);
}
public int getColumnNumber() {
return getCurrentLocation().getColumnNumber();
}
public int getLineNumber() {
return getCurrentLocation().getLineNumber();
}
public String getPublicId() {
return getCurrentLocation().getPublicId();
}
public String getSystemId() {
return getCurrentLocation().getSystemId();
}
},nsc);
}
示例7: evaluateXPathMultiNode
import javax.xml.namespace.NamespaceContext; //导入依赖的package包/类
private NodeList evaluateXPathMultiNode(Node bindings, Node target, String expression, NamespaceContext namespaceContext) {
NodeList nlst;
try {
xpath.setNamespaceContext(namespaceContext);
nlst = (NodeList) xpath.evaluate(expression, target, XPathConstants.NODESET);
} catch (XPathExpressionException e) {
reportError((Element) bindings, WsdlMessages.INTERNALIZER_X_PATH_EVALUATION_ERROR(e.getMessage()), e);
return null; // abort processing this <jaxb:bindings>
}
if (nlst.getLength() == 0) {
reportError((Element) bindings, WsdlMessages.INTERNALIZER_X_PATH_EVALUATES_TO_NO_TARGET(expression));
return null; // abort
}
return nlst;
}
示例8: testNamespaceContext
import javax.xml.namespace.NamespaceContext; //导入依赖的package包/类
@Test
public void testNamespaceContext() {
is = new java.io.ByteArrayInputStream(getXML().getBytes());
try {
XMLStreamReader sr = factory.createFilteredReader(factory.createXMLStreamReader(is), (StreamFilter) filter);
while (sr.hasNext()) {
int eventType = sr.next();
if (eventType == XMLStreamConstants.START_ELEMENT) {
if (sr.getLocalName().equals(childElement)) {
NamespaceContext context = sr.getNamespaceContext();
Assert.assertTrue(context.getPrefix(namespaceURIApple).equals(prefixApple));
}
}
}
} catch (Exception ex) {
Assert.fail("Exception: " + ex.getMessage());
}
}
示例9: switchToXML11Scanner
import javax.xml.namespace.NamespaceContext; //导入依赖的package包/类
private void switchToXML11Scanner() throws IOException{
int oldEntityDepth = fScanner.fEntityDepth;
com.sun.org.apache.xerces.internal.xni.NamespaceContext oldNamespaceContext = fScanner.fNamespaceContext;
fScanner = new XML11NSDocumentScannerImpl();
//get the new scanner state to old scanner's previous state
fScanner.reset(fPropertyManager);
fScanner.setPropertyManager(fPropertyManager);
fEntityScanner = (XMLEntityScanner)fEntityManager.getEntityScanner() ;
fEntityManager.fCurrentEntity.mayReadChunks = true;
fScanner.setScannerState(XMLEvent.START_DOCUMENT);
fScanner.fEntityDepth = oldEntityDepth;
fScanner.fNamespaceContext = oldNamespaceContext;
fEventType = fScanner.next();
}
示例10: getNamespaceContext
import javax.xml.namespace.NamespaceContext; //导入依赖的package包/类
private static NamespaceContext getNamespaceContext() {
//schema related
namespaces.put("xsd","http://www.w3.org/2001/XMLSchema");
prefixes.put("http://www.w3.org/2001/XMLSchema", "xsd");
//wsdl related
namespaces.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
prefixes.put("http://schemas.xmlsoap.org/wsdl/", "wsdl");
return new HashNamespaceResolver(namespaces, prefixes);
}
示例11: namespaceContextForSaml
import javax.xml.namespace.NamespaceContext; //导入依赖的package包/类
private NamespaceContext namespaceContextForSaml() {
NamespaceContextImpl context = new NamespaceContextImpl();
context.startPrefixMapping("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
context.startPrefixMapping("saml2p", "urn:oasis:names:tc:SAML:2.0:protocol");
context.startPrefixMapping("saml2", "urn:oasis:names:tc:SAML:2.0:assertion");
context.startPrefixMapping("ds", "http://www.w3.org/2000/09/xmldsig#");
return context;
}
示例12: getXPath
import javax.xml.namespace.NamespaceContext; //导入依赖的package包/类
public XPath getXPath(NamespaceContext namespaceContext)
{
XPathFactory xPathFactory = buildXPathFactory();
configure(xPathFactory);
XPath xPath = buildXPath(xPathFactory);
configure(xPath, namespaceContext);
return xPath;
}
示例13: shouldParsePrefixedXPath
import javax.xml.namespace.NamespaceContext; //导入依赖的package包/类
@Theory
public void shouldParsePrefixedXPath(@FromDataPoints("Positive-Prefixed") Triple<String, Expr, Expr> data,
@FromDataPoints("namespaceContexts") NamespaceContext context)
throws XPathExpressionException {
Expr actualExpr = new XPathParser(context).parse(data.getFirst());
assertThat(actualExpr).hasToString(null == context ? data.getSecond().toString() : data.getThird().toString());
}
示例14: marshal
import javax.xml.namespace.NamespaceContext; //导入依赖的package包/类
/**
* @since 2.0.2
*/
public void marshal(T object,OutputStream output, NamespaceContext nsContext, AttachmentMarshaller am) throws JAXBException {
Marshaller m = context.marshallerPool.take();
m.setAttachmentMarshaller(am);
marshal(m,object,output,nsContext);
m.setAttachmentMarshaller(null);
context.marshallerPool.recycle(m);
}
示例15: selectSingle
import javax.xml.namespace.NamespaceContext; //导入依赖的package包/类
public XSComponent selectSingle(String scd, NamespaceContext nsContext) {
try {
return SCD.create(scd,nsContext).selectSingle(this);
} catch (ParseException e) {
throw new IllegalArgumentException(e);
}
}