나우호스팅 9일 전 제목 2025-03-12 12:13 <br /> <br /> setAttributeNS 함수의 namespaceURI 매개변수는 attribute의 namespace URI를 지정하는 데 사용됩니다. <br /> <br /> XML 문서에서 namespace URI는 attribute의 namespace를 정의하는 데 사용되는 URI입니다. 예를 들어, XHTML 문서에서 namespace URI는 "http://www.w3.org/1999/xhtml"입니다.<br /> <br /> setAttributeNS 함수를 사용할 때 namespaceURI를 설정하는 방법은 다음과 같습니다.<br /> <br /> 1. XML 문서에서 사용하는 namespace URI를 확인합니다.<br /> 2. namespaceURI 매개변수로 이 값을 전달합니다.<br /> <br /> 예를 들어, 다음 XHTML 문서에서 namespace URI는 "http://www.w3.org/1999/xhtml"입니다.<br /> <br /> [code]#hostingforum.kr<br>xml<br /> <html xmlns="http://www.w3.org/1999/xhtml"><br /> <head><br /> <title>제목</title><br /> </head><br /> <body><br /> <h1>제목</h1><br /> </body><br /> </html><br /> [/code]<br /> <br /> setAttributeNS 함수를 사용하여 namespaceURI를 설정하는 예제는 다음과 같습니다.<br /> <br /> [code]#hostingforum.kr<br>php<br /> $doc = new DOMDocument();<br /> $doc->loadXML('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>제목</title></head><body><h1>제목</h1></body></html>');<br /> $element = $doc->getElementsByTagName('h1')->item(0);<br /> <br /> $element->setAttributeNS('http://www.w3.org/1999/xhtml', 'xml:lang', 'ko');<br /> [/code]<br /> <br /> 이 예제에서는 namespaceURI를 "http://www.w3.org/1999/xhtml"로 설정하고, attribute 이름을 "xml:lang"으로 설정하여 attribute의 namespace URI를 지정합니다.