xml-namespaces

Why is there no XPath syntax for namespace-qualified nodes?

别等时光非礼了梦想. 提交于 2019-12-03 19:52:36
问题 Some of the nodes in an XML document have namespaces, specified with a defined prefix. It is possible to specify local-name() in XPath 1.0 and so ignore namespaces. However, I want to enable the writer of the XPath to find nodes using their full namespace-qualified name as an identifier. The recommended way is to add namespace declarations in the invoking code (in my case, Java). But this means that the person writing Xpath does not have the ability to work with namespaces! How do we find

How do I remove namespaces from xml, using java dom?

一笑奈何 提交于 2019-12-03 17:22:50
问题 I have the following code DocumentBuilderFactory dbFactory_ = DocumentBuilderFactory.newInstance(); Document doc_; DocumentBuilder dBuilder = dbFactory_.newDocumentBuilder(); StringReader reader = new StringReader(s); InputSource inputSource = new InputSource(reader); doc_ = dBuilder.parse(inputSource); doc_.getDocumentElement().normalize(); Then I can do doc_.getDocumentElement(); and get my first element but the problem is instead of being job the element is tns:job . I know about and have

Validation of XML Sitemap urlset with xhtml:link inside url element

寵の児 提交于 2019-12-03 16:33:52
I am trying to create a sitemap such as the below and I get this error: <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xhtml:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> <url> <loc>http://www.something.com/something</loc> <xhtml:link rel="alternate" hreflang="en-us" href="http://www.something.com/something" /> </url> </urlset> Error: http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd "> ^ Error 1866: Element '{ http://www

Using JDK's JAXB without ns2 prefix

半城伤御伤魂 提交于 2019-12-03 16:32:31
问题 After having read all posts about this on Oracle forums, Stackoverflow, java.net I'm finally posting here. I'm using JAXB to create XML files but the problem is that it adds the famous ns2 prefix before my elements, I have tried all the solutions no one worked for me. java -version gives "1.6.0_37" Solution 1 : Using package-info.java I created the file in my package containing my @Xml* annotated classes with the following content : @XmlSchema( namespace = "http://mynamespace",

remove xmlns attribute from the root element while marshalling jaxb

我怕爱的太早我们不能终老 提交于 2019-12-03 16:07:36
This might be a related to JAXB Marshaller - How do I suppress xmlns namespace attributes? But my problem is a little different. I do the regular java marshalling and my xsd has no namespaces.The generated xml is without namespaces as well, except for the root element. <?xml version="1.0" encoding="UTF-8"?><rootElement xmlns:ns2="unwanted namespace"> The unwanted namespace is from another schema from the same project and I am not sure why that is being picked up at this stage. My rootElement.java generated by jaxb2-maven-plugin looks like : @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name =

C# - Add XML Namespace (xmlns) tag to document

空扰寡人 提交于 2019-12-03 14:42:21
I'm creating an XML document using System.XML in C#. I'm almost done, but I need to add some similar to the following to the top of my document: <ABC xmlns="http://www.acme.com/ABC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" fileName="acmeth.xml" date="2011-09-16T10:43:54.91+01:00" origin="TEST" ref="XX_88888"> I need to add this just below where I have: <?xml version="1.0" encoding="UTF-8"?> I create this using the following code: XmlWriterSettings settings = new XmlWriterSettings { Encoding = Encoding.UTF8, Indent = true }; After this I go on to create my XML document, which is

Python lxml iterfind w/ namespace but prefix=None

风格不统一 提交于 2019-12-03 14:41:22
I want to perform iterfind() for elements which have a namespace but no prefix. I'd like to call iterfind([tagname]) or iterfind([tagname], [namespace dict]) I don't care to enter the tag as follows every time: "{%s}tagname" % tree.nsmap[None] Details I'm running through an xml response from a Google API. The root node defines several namespaces, including one for which there is no prefix: xmlns="http://www.w3.org/2005/Atom" It looks as though when I try to search through my etree, everything behaves as I would expect for elements with a prefix. e.g.: >>> for x in root.iterfind('dxp:segment'):

XSLT root tag namespace instead of element attribute namespace

房东的猫 提交于 2019-12-03 13:21:52
I have a XSL file to transfer another XSL file. I want the namespace declaration to be on the root tag, instead of it being repeated on every single element!! Here is my stylesheet: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:mynamespace="somenamespace" version="2.0"> <xsl:output method="xml" omit-xml-declaration="no" standalone="yes" indent="yes" /> <xsl:template match="myMatchedNode"> <mynamespace:tag>Some text i want inserted into the xsl</mynamespace:tag> <xsl:copy> <xsl:apply-templates select="@*|node()" /></xsl:copy> </xsl:template> </xsl:stylesheet> It outputs

Find all namespace declarations in an XML document - xPath 1.0 vs xPath 2.0

孤街醉人 提交于 2019-12-03 08:46:20
问题 As part of a Java 6 application, I want to find all namespace declarations in an XML document, including any duplicates. Edit : Per Martin's request, here's the Java code I am using: XPathFactory xPathFactory = XPathFactory.newInstance(); XPath xPath = xPathFactory.newXPath(); XPathExpression xPathExpression = xPathExpression = xPath.compile("//namespace::*"); NodeList nodeList = (NodeList) xPathExpression.evaluate(xmlDomDocument, XPathConstants.NODESET); Suppose I have this XML document: <

Spring 3 applicationContext-security-JDBC.xml has beans:bean not bean?

隐身守侯 提交于 2019-12-03 08:43:16
can someone please tell me what in my ApplicationContext I have to use beans:bean and not bean and how to fix it. <?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema