Python – 간단한 minidom 사용법

 
xml.dom.minidom:







   1 from xml.dom.minidom import parse, parseString
2
3 dom1 = parse( “foaf.rdf” ) # parse an XML file
4 dom2 = parseString( “<myxml>Some data <empty/> some more data</myxml>” )
5 print dom1.toxml()
6 print dom2.toxml()


Examples of Use



  • node.nodeName
  • node.nodeValue
  • node.childNodes


Find Elements


You can manually walk through the childNodes tree, comparing nodeNames.

You might be able to use getElementsByTagName as well:




   1 from xml.dom.minidom import parse
2 dom = parse(“foo.xml”)
3 for node in dom.getElementsByTagName(‘bar’): # visit every node <bar />
4 print node.toxml()

getElementsByTagName, works recursively into the tree, I believe.


Add an Element


Create & add an XML element (Something like <foo />) to an XML document.




   1 from xml.dom.minidom import parse
2 dom = parse(“bar.xml”)
3 x = dom.createElement(“foo”) # creates <foo />
4 dom.childNodes[1].appendChild(x) # appends at end of 1st child’s children
5 print dom.toxml()


Add an Element with Text Inside


Create & add an XML element to an XML document, the element has text inside.

ex: <foo>hello, world!</foo>




   1 from xml.dom.minidom import parse
2 dom = parse(“bar.xml”)
3 x = dom.createElement(“foo”) # creates <foo />
4 txt = dom.createTextNode(“hello, world!”) # creates “hello, world!”
5 x.appendChild(txt) # results in <foo>hello, world!</foo>
6 dom.childNodes[1].appendChild(x) # appends at end of 1st child’s children
7 print dom.toxml()


Import a Node


You can use DOM 2 “importNode” to take part of one XML document, and put it into another XML document.




   1 from xml.dom.minidom import parse
2 dom1 = parse(“foo.xml”)
3 dom2 = parse(“bar.xml”)
4 x = dom1.importNode(dom2.childNodes[1], # take 2nd node in “bar.xml”
5 True) # deep copy
6 dom1.childNodes[1].appendChild(x) # append to children of 2nd node in “foo.xml”
7 print dom1.toxml()


Links




See Also


출처 http://wiki.python.org/moin/MiniDom

xml문서 만들기

from xml.dom import minidom

# New document
xml = minidom.Document()

Actually the how-to could be finished here, but I will show a little bit more about the minidom.

The next snippet shows how to create an element, set attributes and add this on our document created in the last step.

# Creates user element
userElem = xml.createElement(“user”)

# Set attributes to user element
userElem.setAttribute(“name”, “Sergio Oliveira”)
userElem.setAttribute(“nickname”, “seocam”)
userElem.setAttribute(“email”, “seocam@seocam.net”)
userElem.setAttribute(“photo”,”seocam.png”)

# Append user element in xml document
xml.appendChild(userElem)


If you know the DOM specification nothing until here is new for you, but the next 2 snippets shows how to return a string and how to write a file with our xml document.
# Print the xml code
print xml.toxml(“UTF-8″)
fp = open(“file.xml”,”w”)
xml.writexml(fp, ” “, “”, “\n”, “UTF-8″)

# Method’s stub
# writexml(self, writer, indent=”, addindent=”, newl=”, encoding=None)


The result generated by both methods:
<?xml version=”1.0″ encoding=”UTF-8″?>
<user email=”seocam@seocam.net” name=”Sergio Oliveira”
nickname=”seocam” photo=”seocam.png”>

출처 http://www.seocam.net/how-tos/creating-a-new-xml-document-with-python-minidom

ora-12638 credential retrieval failed

ora-12638 credential retrieval failed 에 대한 Oracle 포럼 에 올라와 있는 답변

Hi JA,

I’m no Oracle expert, but from what can make out the NTS option makes the Oracle client attempt to use your current Windows domain credentials to authenticate you with the Oracle server. This could fail for a couple of reasons:

– The Oracle server is not configured to support Windows authentication
– The credentials you use to login to your local machine are not sufficient to allow you to login to the server.

In my case, it was the later. Despite the fact that I had told the client to use a different user name and password, it was still attempting to login using my domain credentials first. This failed because I was logged on to my local machine using my normal domain credentials rather than my administrator account.

Replacing the line:

SQLNET.AUTHENTICATION_SERVICES= (NTS)

with

SQLNET.AUTHENTICATION_SERVICES= (NONE)

in sqlnet.ora resolved the issue by disabling local support for authenticating using Windows credentials.

HTH,
Carey

출처 – oracle forum
http://forums.oracle.com/forums/thread.jspa?threadID=332525

상속계층의 표현

상속계층에 있는 클래스를 다음과 같이 클래스 별로 Table을 등록

public class Item {
 private int itemNumber;
 private String itemName;
 ….
}

public class LargeItem extends Item {
 private Vector middleItemList;
 …
}

<hibernate-mapping package=”net.maxoft.session.beans”>
  <class name=”Item” table=”CategoryItem”>
      <id name=”itemNumber” column=”Id”  unsaved-value=”null”>
          <generator class=”increment”/>
      </id>    
      <property name=”itemName” column=”CategoryName”/>  
     
      <joined-subclass name=”LargeItem” table=”LargeCategory”>
          <key column=”Id”/>         
          <bag name=”middleItemList”>
              <key column=”parentItem”/>
              <one-to-many class=”MiddleItem”/>
          </bag>             
      </joined-subclass>
  </class>
</hibernate-mapping>