xml-namespaces

Nesting XML elements from different namespaces in XSD

烂漫一生 提交于 2020-01-03 19:31:27
问题 Assume that I have an XML schema definition for elements of a namespace that I would like to use as child elements of XML elements within a second namespace. As an example, suppose we have file foo.xsd : <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns="urn:foo-ns" targetNamespace="urn:foo-ns" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="foo" type="fooType"/> <xs:complexType name="fooType"> <xs:attribute name="id" use="required"/> </xs

How to preserve namespaces when parsing xml via ElementTree in Python

半世苍凉 提交于 2020-01-03 02:57:21
问题 Assume that I've the following XML which I want to modify using Python's ElementTree : <root xmlns:prefix="URI"> <child company:name="***"/> ... </root> I'm doing some modification on the XML file like this: import xml.etree.ElementTree as ET tree = ET.parse('filename.xml') # XML modification here # save the modifications tree.write('filename.xml') Then the XML file looks like: <root xmlns:ns0="URI"> <child ns0:name="***"/> ... </root> As you can see, the namepsace prefix changed to ns0 . I'm

How to preserve namespaces when parsing xml via ElementTree in Python

喜你入骨 提交于 2020-01-03 02:57:04
问题 Assume that I've the following XML which I want to modify using Python's ElementTree : <root xmlns:prefix="URI"> <child company:name="***"/> ... </root> I'm doing some modification on the XML file like this: import xml.etree.ElementTree as ET tree = ET.parse('filename.xml') # XML modification here # save the modifications tree.write('filename.xml') Then the XML file looks like: <root xmlns:ns0="URI"> <child ns0:name="***"/> ... </root> As you can see, the namepsace prefix changed to ns0 . I'm

How to append node and attribute to an existing Xml file

∥☆過路亽.° 提交于 2020-01-02 23:26:30
问题 I have the following XML file. I have to add a node using XElement and XAttribute . How to do this? <?xml version="1.0" encoding="UTF-8"?> <Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"> <DataSets> <DataSet Name="Data"> <Query> <DataSourceName>DS1</DataSourceName> <CommandText>SELECT FirstName,LastName FROM Person</CommandText> </Query> </DataSet> <DataSet Name="table22">

Extract value from xml file with namespaces by using xmllint in bash

一世执手 提交于 2020-01-02 19:10:33
问题 I need to extract the name value (Product Finder) from this xml: File: config.xml <?xml version="1.0" encoding="utf-8"?> <widget id="com.abc.app" version="1.3.1" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0" ios-CFBundleVersion="1.3.1.5" android-versionCode="5"> <name>Product Finder</name> <description> Description </description> </widget> I've tried: mles$ xmllint --xpath "/widget/name/text()"

atom feed xmlns attribute messes up AS3's XML-parsing?

纵然是瞬间 提交于 2020-01-02 08:34:44
问题 Wanna see something interesting? var xml:XML = XML(<feed><entry /><entry /><entry /></feed>); trace(xml.entry.length()) // returns 3 Makes sense, right? Now let's add this attribute... var xml:XML = XML(<feed xmlns="http://www.w3.org/2005/Atom"><entry /><entry /><entry /></feed>); trace(xml.entry.length()) // returns 0 Well that can't be right. Let's try it with a different attribute. var xml:XML = XML(<feed test="okay"><entry /><entry /><entry /></feed>); trace(xml.entry.length()) // returns

XPath how to identify an attribute in a predicate in a namespace-unaware way [duplicate]

主宰稳场 提交于 2020-01-01 12:01:46
问题 This question already has answers here : Select xml node by attribute name ignoring namespace of that attribute (2 answers) Closed 5 years ago . I have the following XML file: <foo:a xmlns:foo=\"http://www.foo.com\"> <foo:b foo:bar=\"zar\"> </foo:b> </foo:a> To get the b nodes with an attribute bar having the value "zar" (all in the correct namespace), I can use the XPath expression: /foo:a/foo:b[@foo:bar=\"zar\"] (with "foo" properly bound to "http://www.foo.com" - see code at the end)

JAXB: Namespace annotation not inherited during unmarshalling - regression in JDK 1.8_102?

瘦欲@ 提交于 2019-12-30 22:57:16
问题 I ran into a situation where JAXB refuses to unmarshal an XML element unless the corresponding Java field has a namespace annotation. This behavior only started in JDK 1.8.0_111 (or possibly in 102). Earlier versions of JDK 1.8 work. Test case: Java class (shortened): package my.package; @XmlRootElement(name = "MyElement", namespace="myns") public class MyElement { @XmlElement(name = "subEl") private String subEl; } XML: <MyElement xmlns="myns"> <subEl>text1</subEl> </MyElement> package-info

JAXB: Namespace annotation not inherited during unmarshalling - regression in JDK 1.8_102?

大兔子大兔子 提交于 2019-12-30 22:56:13
问题 I ran into a situation where JAXB refuses to unmarshal an XML element unless the corresponding Java field has a namespace annotation. This behavior only started in JDK 1.8.0_111 (or possibly in 102). Earlier versions of JDK 1.8 work. Test case: Java class (shortened): package my.package; @XmlRootElement(name = "MyElement", namespace="myns") public class MyElement { @XmlElement(name = "subEl") private String subEl; } XML: <MyElement xmlns="myns"> <subEl>text1</subEl> </MyElement> package-info

JAXB: Namespace annotation not inherited during unmarshalling - regression in JDK 1.8_102?

∥☆過路亽.° 提交于 2019-12-30 22:55:14
问题 I ran into a situation where JAXB refuses to unmarshal an XML element unless the corresponding Java field has a namespace annotation. This behavior only started in JDK 1.8.0_111 (or possibly in 102). Earlier versions of JDK 1.8 work. Test case: Java class (shortened): package my.package; @XmlRootElement(name = "MyElement", namespace="myns") public class MyElement { @XmlElement(name = "subEl") private String subEl; } XML: <MyElement xmlns="myns"> <subEl>text1</subEl> </MyElement> package-info