xml-namespaces

Attribute XmlNamespaceDeclarations is ignored during XML serialization

点点圈 提交于 2019-11-28 08:50:52
问题 I try to serialize an object with custom namespaces. This is how the class looks like: [XmlRoot("Root", Namespace = "myNamespace")] public partial class MyClass { public MyClass() { this.Xmlns = new XmlSerializerNamespaces(); this.Xmlns.Add(string.Empty, "myNamespace"); } [XmlNamespaceDeclarations()] public XmlSerializerNamespaces Xmlns = null; } And here is the code to serialize it: XmlSerializer serializer = new XmlSerializer(typeof(MyClass)); serializer.Serialize(xmlWriter, obj); The

XML + XPATH: Any way to work with a default Namespace?

佐手、 提交于 2019-11-28 08:49:23
问题 I have a XML SOAP result: <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <CreateCIInStockResponse xmlns="http://somenamespace.com/"> <CreateCIInStockResult> <Status>OK</Status> <Data>SOMERESULT</Data> </CreateCIInStockResult> </CreateCIInStockResponse> </soap:Body> </soap:Envelope> As you can see, the namespace defined in

How can I strip namespaces out of an lxml tree?

跟風遠走 提交于 2019-11-28 08:46:16
Following on from Removing child elements in XML using python ... Thanks to @Tichodroma, I have this code: If you can use lxml , try this: import lxml.etree tree = lxml.etree.parse("leg.xml") for dog in tree.xpath("//Leg1:Dog", namespaces={"Leg1": "http://what.not"}): parent = dog.xpath("..")[0] parent.remove(dog) parent.text = None tree.write("leg.out.xml") Now leg.out.xml looks like this: <?xml version="1.0"?> <Leg1:MOR xmlns:Leg1="http://what.not" oCount="7"> <Leg1:Order> <Leg1:CTemp id="FO"> <Leg1:Group bNum="001" cCount="4"/> <Leg1:Group bNum="002" cCount="4"/> </Leg1:CTemp> <Leg1:CTemp

Weirdness with XDocument, XPath and namespaces

十年热恋 提交于 2019-11-28 08:32:28
I have an XML document that looks like this: <kmsg xmlns="http://url1" xmlns:env="url1" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance" xsi:schemaLocation="http://location that does not exist.xsd"> <header> <env:envelope> <env:source branch="907" machine="0" password="J123"/> </env:envelope> </header> <body> <OrderResponse xmlns="urn:schemasbasdaorg:2000:orderResponse:xdr:3.01"> <SomeMoreNodes/> </OrderResponse> </body> It does not have any schemas available despite having namespaces specified (I'm getting this from an external source so have no control). I'm parsing it with an XDocument,

Xpath fails if an element has a a xmlns attribute [duplicate]

☆樱花仙子☆ 提交于 2019-11-28 07:55:26
问题 Possible Duplicate: xPath finds nothing but * Im trying to use xml to parse a .COLLADA file. The problem is I can't seem to use xpath() to access elements if the root tag has a xmlns attribute. For example this works: $string = <<<TEST <?xml version="1.0" encoding="utf-8"?> <COLLADA version="1.4.1"> <library_materials> <material id="Material" name="Material"> <instance_effect url="#Material-effect"/> </material> <material id="Material2" name="Material"> <instance_effect url="#Material-effect2

Define a default namespace for use in XSL XPaths with xpath-default-namespace

隐身守侯 提交于 2019-11-28 07:12:30
问题 I have this simple xml document: <?xml version='1.0' encoding='UTF-8'?> <registry xmlns="http://www.iana.org/assignments" id="character-sets"> <registry id="character-sets-1"> <record> <name>ANSI_X3.4-1968</name> </record> </registry> </registry> When I use this xsl I can extract the name: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="http://www.iana.org/assignments" version="1.0"> <xsl:template match="/my:registry"> <xsl

How to declare an XML namespace prefix with DOM/PHP?

痴心易碎 提交于 2019-11-28 04:44:07
问题 I'm trying to produce the following XML by means of DOM/PHP5: <?xml version="1.0"?> <root xmlns:p="myNS"> <p:x>test</p:x> </root> This is what I'm doing: $xml = new DOMDocument('1.0'); $root = $xml->createElementNS('myNS', 'root'); $xml->appendChild($root); $x = $xml->createElementNS('myNS', 'x', 'test'); $root->appendChild($x); echo $xml->saveXML(); This is what I'm getting: <?xml version="1.0"?> <root xmlns="myNS"> <x>test</x> </root> What am I doing wrong? How to make this prefix working?

Java XPath: Queries with default namespace xmlns

妖精的绣舞 提交于 2019-11-28 03:53:34
问题 I want to do an XPath query on this file (excerpt shown): <?xml version="1.0" encoding="UTF-8"?> <!-- MetaDataAPI generated on: Friday, May 25, 2007 3:26:31 PM CEST --> <ModelClass xmlns="http://xml.sap.com/2002/10/metamodel/webdynpro" xmlns:IDX="urn:sap.com:WebDynpro.ModelClass:2.0"> <ModelClass.Parent> <Core.Reference package="com.test.mypackage" name="ModelName" type="Model"/> This is a snippet of the code I'm using: DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();

Select node without namespace with XPath

不打扰是莪最后的温柔 提交于 2019-11-28 03:25:43
问题 I have a xml like <root xmlns:ns1="http://foo"> <ns1:child1>Text</ns1:child1> <ns1:child2>Number</ns1:child2> </root> Now I get this from different persons, so that for example person 2 sends me another message with the same structure like <root xmlns:anotherNs="http://foo"> <anotherNs:child1>Another Text</anotherNs:child1> <anotherNs:child2>Another Number</anotherNs:child2> </root> So the only difference is the name of the namespace. How can I select the content of child2 for both xml's with

How do I select nodes that use a default namespace?

寵の児 提交于 2019-11-28 02:18:17
The structure of the XML file is more or less as follows: <?xml version="1.0" encoding="UTF-8"?> <a xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="url1" xsi:schemaLocation="url2 url3"> <b> <c></c> <c></c> <c></c> </b> </a> My goal is to select all the "c" elements, but the following xpath expression won't work: "//a/b/c". ie: XmlDocument doc= new XmlDocument(); doc.Load(filepath); XmlNodeList l = doc.SelectNodes("//a/b/c"); // 0 nodes The only xpath expressions I tested that worked are /* (1 node) and //* (all nodes). Is this problem related to the XML namespace? If so, what's