xml-namespaces

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

a 夏天 提交于 2019-11-29 13:17:09
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:copy-of select="//my:record/my:name"/> </xsl:template> </xsl:stylesheet> However, If I omit the namespace

Is xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” a special case in XML?

强颜欢笑 提交于 2019-11-29 13:15:37
问题 When we use a namespace, we should also indicate where its associated XSD is located at, as can be seen in the following example: <?xml version="1.0"?> <Artist BirthYear="1958" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.webucator.com/Artist" xsi:schemaLocation="http://www.webucator.com/Artist Artist.xsd"> <Name> <Title>Mr.</Title> <FirstName>Michael</FirstName> <LastName>Jackson</LastName> </Name> </Artist> Here, we have indicated that Artist.xsd should be used

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

情到浓时终转凉″ 提交于 2019-11-29 10:57:42
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? $root = $xml->createElementNS('myNS', 'root'); root shouldn't be in namespace myNS . In the original

Help parsing XML with DOMDocument

╄→尐↘猪︶ㄣ 提交于 2019-11-29 10:48:13
I am trying to parse a youtube playlist field. The URL is: http://gdata.youtube.com/feeds/api/playlists/664AA68C6E6BA19B?v=2 I need: Title, Video ID, and Default thumbnail. I can easily get the title but I'm a little lost when it comes to the nested elements $data = new DOMDocument(); if($data->load("http://gdata.youtube.com/feeds/api/playlists/664AA68C6E6BA19B?v=2")) { foreach ($data->getElementsByTagName('entry') as $video) { $title = $video->getElementsByTagName('title')->item(0)->nodeValue; $id = ?? $thumb = ?? } } Here is the XML (I have stripped out the elements that are irrelevant for

Java XPath: Queries with default namespace xmlns

。_饼干妹妹 提交于 2019-11-29 10:31:23
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(); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document document = builder.parse(new File

Is xmlns=“” a valid xml namespace?

£可爱£侵袭症+ 提交于 2019-11-29 09:05:27
Is "empty" a valid value for XML namespace? If yes what does it mean? I have the following XML code but I'm not sure to which namespace Field1 and Field2 elements belong to. <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header /> <soap:Body> <Root xmlns="uri"> <Field1 xmlns="">147079737</Field1> <Field2 xmlns="">POL</Field2> </Root> </soap:Body> </soapenv:Envelope> Frerich Raabe Yes, it is valid. Section 6.2 in the Namespaces in XML 1.0 Recommendation specifically says: The attribute value in a default namespace declaration MAY be empty. This has the

How to detect and remove unnecessary xmlns:<something> attributes in PHP DOM?

余生颓废 提交于 2019-11-29 08:38:56
Say I have a source document like this: <element> <subelement xmlns:someprefix="mynamespace"/> </element> The xmlns:someprefix is obviously not needed here and doesn't do anything since that prefix is not being used in that element (or in my case, anywhere in the document). In PHP, after I've loaded this into a DOM tree with DOMDocument->loadXML(), I'd like to be able to detect that such a namespace declaration exists, and remove it. I know that I can read it with hasAttribute() and even remove it with removeAttributeNS() (strangely) but only if I know its prefix. It doesn't appear in DOMNode-

Unable to add Attribute with Namespace Prefix using PHP Simplexml

北战南征 提交于 2019-11-29 07:55:43
Trying to edit an XML document that uses Excels XML-Namespaces: <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"> I need to get to this result (need the ss: prefix befire Type ): <Cell ...><Data ss:Type="String">value</Data></Cell> I've looked over the question Unable add namespace with PHPs SimpleXML but this method is not helping here. In other words, running this as outlined there $data = $cells[$i]->addChild('Data','value'); $data->addAttribute("ss:Type","String","urn:schemas-microsoft-com:office:spreadsheet"); gives me

XSL - copy elements but remove unused namespace(s)

独自空忆成欢 提交于 2019-11-29 06:12:42
问题 I've got some XML which declares a namespace which is only used for attributes, like this: <?xml version="1.0" encoding="UTF-8"?> <a xmlns:x="http://tempuri.com"> <b> <c x:att="true"/> <d>hello</d> </b> </a> I want to use XSL to create a copy of selected nodes and their values - getting rid of the attributes. So my desired output is: <?xml version="1.0" encoding="UTF-8"?> <b> <c /> <d>hello</d> </b> I've got some XSL that almost does this, but I can't seem to stop it putting the namespace

HTML5 <html> attributes xmlns, lang, xml:lang

淺唱寂寞╮ 提交于 2019-11-29 06:07:34
问题 I don't understand the HTML5 specifications for the lang and xml:lang attributes of the opening <html> tag. Scrolling up a bit, I understand that xmlns is a "talisman" (has no effect), but what about lang and xml:lang ? Should they be used? If so, what should they be set to? 回答1: Everything I've seen and heard suggests that you should stick to <!DOCTYPE html> <html> <head> <meta charset='UTF-8'> (or whatever character set you actually want). If you want a language associated with the page you