xml-namespaces

Rewrite XMLDocument to use namespace prefix

心不动则不痛 提交于 2020-12-13 07:12:53
问题 I have a XMLDocument which, when I save to file, repeats a namespace on most of the elements, as in <Test> <Test xmlns="http://example.com/schema1"> <Name xmlns="http://example.com/schema2">xyz</Name> <AddressInfo xmlns="http://example.com/schema2"> <Address>address</Address> <ZipCode>zzzz</ZipCode> </AddressInfo> ... Is it possible to amend this file so that it uses a namespace prefix throughout the document, ie something like <Test xmlns="http://example.com/schema1" xmlns:p="http://example

Parsing XML with undeclared prefixes in Python

懵懂的女人 提交于 2020-12-02 07:47:08
问题 I am trying to parse XML data with Python that uses prefixes, but not every file has the declaration of the prefix. Example XML: <?xml version="1.0" encoding="UTF-8"?> <item subtype="bla"> <thing>Word</thing> <abc:thing2>Another Word</abc:thing2> </item> I have been using xml.etree.ElementTree to parse these files, but whenever the prefix is not properly declared, ElementTree throws a parse error. ( unbound prefix , right at the start of <abc:thing2> ) Searching for this error leads me to

Parsing XML with undeclared prefixes in Python

天涯浪子 提交于 2020-12-02 07:46:15
问题 I am trying to parse XML data with Python that uses prefixes, but not every file has the declaration of the prefix. Example XML: <?xml version="1.0" encoding="UTF-8"?> <item subtype="bla"> <thing>Word</thing> <abc:thing2>Another Word</abc:thing2> </item> I have been using xml.etree.ElementTree to parse these files, but whenever the prefix is not properly declared, ElementTree throws a parse error. ( unbound prefix , right at the start of <abc:thing2> ) Searching for this error leads me to

Python ElementTree find() using namespaces

时光怂恿深爱的人放手 提交于 2020-03-24 00:38:02
问题 I am attempting to use Python’s ElementTree to parse and modify an xml file. The confusion comes with the XML Namespace. I can use the findall and finditer to get all of the servers names. However, I can't get the xpath query to work to find a specific server. instead the find just brings back the parent element. What I need to do is find the correct server by the “name” or “machine” element and modify the “arguments”. <? xml version=’1.0’ encoding=’UTF-8’?> <domain xmlns=”http://xmlns.oracle

Java XML parser adding unnecessary xmlns and xml:space attributes

给你一囗甜甜゛ 提交于 2020-03-19 06:17:11
问题 This bounty has ended . Answers to this question are eligible for a +50 reputation bounty. Bounty grace period ends in 17 hours . Garret Wilson wants to draw more attention to this question: Surely there must be something going wrong here, especially with the inappropriate xml:space . But what? I'm using Java 11 (AdoptOpenJDK 11.0.5 2019-10-15) on Windows 10. I'm parsing some legacy XHTML 1.1 files, which take the following general form: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html

How to Select XML Nodes with XML Namespaces from an XmlDocument?

爷,独闯天下 提交于 2020-03-07 06:11:32
问题 my code attempts to grab data from the RSS feed of a website. It grabs the nodes fine, but when attempting to grab the data from a node with a colon, it crashes and gives the error "Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function." The code is shown below: WebRequest request = WebRequest.Create("http://buypoe.com/external.php?type=RSS2&lastpost=true"); WebResponse response = request.GetResponse(); StringBuilder sb = new StringBuilder("");

How can I match the xmlns:* attributes with XSLT?

一个人想着一个人 提交于 2020-02-02 07:26:04
问题 How can I match the xmlns:* attributes with XSLT 1.0 ? Using a RDF document I tried: <xs:template match="rdf:RDF"> (...) <xsl:for-each select="@*"> <xsl:value-of select="."/> </xsl:for-each> (...) </xsl:template> but it doesn't seem to work for the xmlns attributes. Thanks. 回答1: The xmlns attributes aren't normal attributes, they are namespace declarations. You need to use the namespace axis to access them. e.g.: <xsl:for-each select="namespace::*"> <xsl:value-of select="name()" /> </xsl:for

XSLT Namespaces

萝らか妹 提交于 2020-01-30 05:19:57
问题 I have a basic question about XSLT Namespaces. XSLT: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="myNamespace" exclude-result-prefixes="x"> <xsl:template match="/"> <newNode> <xsl:value-of select="x:Node1/x:Node2" /> </newNode> </xsl:template> </xsl:stylesheet> This XSLT works correctly when I apply it to: <Node1 xmlns="myNamespace"> <Node2>ValueIWant</Node2> </Node1> But it does not find "ValueIWant" when I apply it to: <ns0:Node1 xmlns:ns0=

XSLT Namespaces

做~自己de王妃 提交于 2020-01-30 05:19:10
问题 I have a basic question about XSLT Namespaces. XSLT: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="myNamespace" exclude-result-prefixes="x"> <xsl:template match="/"> <newNode> <xsl:value-of select="x:Node1/x:Node2" /> </newNode> </xsl:template> </xsl:stylesheet> This XSLT works correctly when I apply it to: <Node1 xmlns="myNamespace"> <Node2>ValueIWant</Node2> </Node1> But it does not find "ValueIWant" when I apply it to: <ns0:Node1 xmlns:ns0=

Adding namespace prefix XML String using XML DOM

微笑、不失礼 提交于 2020-01-30 02:47:18
问题 I want to add namespace prefix to all the elements in the XML String using XML DOM. E.g. My String is coming in this way: <root> <operation>test string</operation> <data> <parameter> <name>test string</name> <value>test string</value> </parameter> <parameter> <name>test string</name> <value>test string</value> </parameter> <parameter> <name>test string</name> <value>test string</value> </parameter> </data> </root> And I want a output XML as: <ns0:root xmlns:ns0 = "http://www.tibco.com/schemas