Changes since
the last release

com.ebay.sdk.util
Class XmlUtil

java.lang.Object
  extended by com.ebay.sdk.util.XmlUtil

public abstract class XmlUtil
extends java.lang.Object

Xml related helper functions.

Title:

Description:

Copyright: Copyright (c) 2004

Company: eBay Inc.

Version:
1.0
Author:
Changyi Zhu, Weijun Li

Constructor Summary
XmlUtil()
           
 
Method Summary
static void appendAttributeNode(org.w3c.dom.Element parent, java.lang.String name, int value)
           
static void appendAttributeNode(org.w3c.dom.Element parent, java.lang.String name, java.lang.String value)
           
static void appendAttributeNode(java.lang.String namespace, org.w3c.dom.Element parent, java.lang.String name, int value)
           
static void appendAttributeNode(java.lang.String namespace, org.w3c.dom.Element parent, java.lang.String name, java.lang.String value)
           
static org.w3c.dom.Element appendChildNode(org.w3c.dom.Document doc, org.w3c.dom.Node parent, java.lang.String name)
           
static org.w3c.dom.Element appendChildNode(org.w3c.dom.Document doc, org.w3c.dom.Node parent, java.lang.String name, int value)
           
static org.w3c.dom.Element appendChildNode(org.w3c.dom.Document doc, org.w3c.dom.Node parent, java.lang.String name, java.lang.String value)
           
static org.w3c.dom.Element appendChildNode(org.w3c.dom.Document doc, java.lang.String namespace, org.w3c.dom.Node parent, java.lang.String name)
           
static org.w3c.dom.Element appendChildNode(org.w3c.dom.Document doc, java.lang.String namespace, org.w3c.dom.Node parent, java.lang.String name, java.lang.String value)
           
static org.w3c.dom.Element appendChildNodeCDATA(org.w3c.dom.Document doc, org.w3c.dom.Node parent, java.lang.String name, int value)
           
static org.w3c.dom.Element appendChildNodeCDATA(org.w3c.dom.Document doc, org.w3c.dom.Node parent, java.lang.String name, java.lang.String value)
           
static org.w3c.dom.Document createDom()
           
static org.w3c.dom.Document createDom(java.io.File file)
          Method to create a DOM document tree from a file
static org.w3c.dom.Document createDom(java.io.InputStream is)
          Method to create a DOM document tree from a InputStream
static org.w3c.dom.Document createDom(java.lang.String xml)
          Method to create a DOM document tree from a valid XML string
static org.w3c.dom.Document createDomByPathname(java.lang.String pathname)
          Method to create a DOM document tree from a fuke
static org.w3c.dom.Node findAttribute(org.w3c.dom.Node node, java.lang.String name)
          Finds attribute of node by name.
static org.w3c.dom.Node findNode(org.w3c.dom.Node node, java.lang.String nodeName)
          Find node by name recursively.
static boolean getAttributeBoolean(org.w3c.dom.Node node, java.lang.String name)
          Gets the boolean value of a named attribute of a node.
static double getAttributeDouble(org.w3c.dom.Node node, java.lang.String name, double errValue)
          Gets the double value of a named attribute of a node.
static int getAttributeInteger(org.w3c.dom.Node node, java.lang.String name, int errValue)
          Gets the integer value of a named attribute of a node.
static java.lang.String getAttributeString(org.w3c.dom.Node node, java.lang.String name)
          Gets the value of a named attribute of a node.
static boolean getChildBoolean(org.w3c.dom.Node node, java.lang.String xpath)
           
static boolean getChildBooleanByName(org.w3c.dom.Node node, java.lang.String nodeName)
          "1" means true.
static org.w3c.dom.Node getChildByName(org.w3c.dom.Node node, java.lang.String nodeName)
          Find node by name.
static java.util.Date getChildDate(org.w3c.dom.Node node, java.lang.String xpath)
           
static double getChildDouble(org.w3c.dom.Node node, java.lang.String xpath)
           
static double getChildDoubleByName(org.w3c.dom.Node node, java.lang.String nodeName, double errValue)
           
static int getChildInteger(org.w3c.dom.Node node, java.lang.String xpath)
           
static int getChildIntegerByName(org.w3c.dom.Node node, java.lang.String nodeName, int errValue)
           
static java.lang.String getChildString(org.w3c.dom.Node node, java.lang.String xpath)
           
static java.lang.String getChildStringByName(org.w3c.dom.Node node, java.lang.String nodeName, java.lang.String errValue)
           
static java.lang.String getChildStringNS(org.w3c.dom.Element element, java.lang.String namespace, java.lang.String childName)
           
static java.lang.String getXmlStringFromDom(org.w3c.dom.Document doc)
          Method to get formatted Xml string from Xml document
static java.lang.String getXmlStringFromSource(javax.xml.transform.Source payload)
          Method to get formatted Xml string from Xml source
static void saveDomToFile(org.w3c.dom.Document doc, java.lang.String filePath)
          Save content of DOM to a file.
static void setChildValue(org.w3c.dom.Document doc, org.w3c.dom.Node parent, java.lang.String childName, int value)
           
static void setChildValue(org.w3c.dom.Document doc, org.w3c.dom.Node parent, java.lang.String childName, java.lang.String value)
           
static java.lang.String xslTransform(org.w3c.dom.Document xmlDoc, org.w3c.dom.Document xslDoc)
          Performs XSL transformation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlUtil

public XmlUtil()
Method Detail

getXmlStringFromSource

public static java.lang.String getXmlStringFromSource(javax.xml.transform.Source payload)
Method to get formatted Xml string from Xml source

Parameters:
payload - Source
Returns:
a formatted Xml string

getXmlStringFromDom

public static java.lang.String getXmlStringFromDom(org.w3c.dom.Document doc)
Method to get formatted Xml string from Xml document

Parameters:
doc -
Returns:
a formatted Xml string

createDom

public static org.w3c.dom.Document createDom(java.lang.String xml)
                                      throws org.xml.sax.SAXException,
                                             java.io.IOException,
                                             javax.xml.parsers.ParserConfigurationException
Method to create a DOM document tree from a valid XML string

Parameters:
xml - String
Returns:
An org.w3c.dom.Document object
Throws:
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException

createDom

public static org.w3c.dom.Document createDom()
                                      throws org.xml.sax.SAXException,
                                             java.io.IOException,
                                             javax.xml.parsers.ParserConfigurationException
Returns:
Document
Throws:
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException

createDom

public static org.w3c.dom.Document createDom(java.io.File file)
                                      throws org.xml.sax.SAXException,
                                             java.io.IOException,
                                             javax.xml.parsers.ParserConfigurationException
Method to create a DOM document tree from a file

Parameters:
file - Source file for the DOM
Returns:
An org.w3c.dom.Document object
Throws:
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException

createDom

public static org.w3c.dom.Document createDom(java.io.InputStream is)
                                      throws org.xml.sax.SAXException,
                                             java.io.IOException,
                                             javax.xml.parsers.ParserConfigurationException
Method to create a DOM document tree from a InputStream

Parameters:
is - InputStream
Returns:
An org.w3c.dom.Document object
Throws:
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException

createDomByPathname

public static org.w3c.dom.Document createDomByPathname(java.lang.String pathname)
                                                throws org.xml.sax.SAXException,
                                                       java.io.IOException,
                                                       javax.xml.parsers.ParserConfigurationException
Method to create a DOM document tree from a fuke

Parameters:
pathname - Source file for the DOM
Returns:
An org.w3c.dom.Document object
Throws:
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException

appendChildNode

public static org.w3c.dom.Element appendChildNode(org.w3c.dom.Document doc,
                                                  org.w3c.dom.Node parent,
                                                  java.lang.String name)
Parameters:
doc - Document
parent - Node
name - String
Returns:
Element

appendChildNode

public static org.w3c.dom.Element appendChildNode(org.w3c.dom.Document doc,
                                                  java.lang.String namespace,
                                                  org.w3c.dom.Node parent,
                                                  java.lang.String name)
Parameters:
doc - Document
namespace - String
parent - Node
name - String
Returns:
Element

appendChildNode

public static org.w3c.dom.Element appendChildNode(org.w3c.dom.Document doc,
                                                  org.w3c.dom.Node parent,
                                                  java.lang.String name,
                                                  int value)
Parameters:
doc - Document
parent - Node
name - String
value - int
Returns:
Element

appendChildNode

public static org.w3c.dom.Element appendChildNode(org.w3c.dom.Document doc,
                                                  org.w3c.dom.Node parent,
                                                  java.lang.String name,
                                                  java.lang.String value)
Parameters:
doc - Document
parent - Node
name - String
value - String
Returns:
Element

appendChildNode

public static org.w3c.dom.Element appendChildNode(org.w3c.dom.Document doc,
                                                  java.lang.String namespace,
                                                  org.w3c.dom.Node parent,
                                                  java.lang.String name,
                                                  java.lang.String value)
Parameters:
doc - Document
namespace - String
parent - Node
name - String
value - String
Returns:
Element

appendAttributeNode

public static void appendAttributeNode(org.w3c.dom.Element parent,
                                       java.lang.String name,
                                       java.lang.String value)
Parameters:
parent - Element
name - String
value - String

appendAttributeNode

public static void appendAttributeNode(java.lang.String namespace,
                                       org.w3c.dom.Element parent,
                                       java.lang.String name,
                                       java.lang.String value)
Parameters:
namespace - String
parent - Element
name - String
value - String

appendAttributeNode

public static void appendAttributeNode(org.w3c.dom.Element parent,
                                       java.lang.String name,
                                       int value)
Parameters:
parent - Element
name - String
value - int

appendAttributeNode

public static void appendAttributeNode(java.lang.String namespace,
                                       org.w3c.dom.Element parent,
                                       java.lang.String name,
                                       int value)
Parameters:
namespace - String
parent - Element
name - String
value - int

appendChildNodeCDATA

public static org.w3c.dom.Element appendChildNodeCDATA(org.w3c.dom.Document doc,
                                                       org.w3c.dom.Node parent,
                                                       java.lang.String name,
                                                       int value)
Parameters:
doc - Document
parent - Node
name - String
value - int
Returns:
Element

appendChildNodeCDATA

public static org.w3c.dom.Element appendChildNodeCDATA(org.w3c.dom.Document doc,
                                                       org.w3c.dom.Node parent,
                                                       java.lang.String name,
                                                       java.lang.String value)
Parameters:
doc - Document
parent - Node
name - String
value - String
Returns:
Element

getChildString

public static java.lang.String getChildString(org.w3c.dom.Node node,
                                              java.lang.String xpath)
                                       throws javax.xml.transform.TransformerException
Parameters:
node - Node
xpath - String
Returns:
String
Throws:
javax.xml.transform.TransformerException

getChildStringNS

public static java.lang.String getChildStringNS(org.w3c.dom.Element element,
                                                java.lang.String namespace,
                                                java.lang.String childName)
Parameters:
element - Element
namespace - String
childName - String
Returns:
String

getChildInteger

public static int getChildInteger(org.w3c.dom.Node node,
                                  java.lang.String xpath)
                           throws javax.xml.transform.TransformerException
Parameters:
node - Node
xpath - String
Returns:
int
Throws:
javax.xml.transform.TransformerException

getChildBoolean

public static boolean getChildBoolean(org.w3c.dom.Node node,
                                      java.lang.String xpath)
                               throws javax.xml.transform.TransformerException
Parameters:
node - Node
xpath - String
Returns:
boolean
Throws:
javax.xml.transform.TransformerException

getChildDouble

public static double getChildDouble(org.w3c.dom.Node node,
                                    java.lang.String xpath)
                             throws javax.xml.transform.TransformerException
Parameters:
node - Node
xpath - String
Returns:
double
Throws:
javax.xml.transform.TransformerException

getChildDate

public static java.util.Date getChildDate(org.w3c.dom.Node node,
                                          java.lang.String xpath)
                                   throws javax.xml.transform.TransformerException,
                                          java.text.ParseException
Parameters:
node - Node
xpath - String
Returns:
Date
Throws:
javax.xml.transform.TransformerException
java.text.ParseException

findNode

public static org.w3c.dom.Node findNode(org.w3c.dom.Node node,
                                        java.lang.String nodeName)
Find node by name recursively.

Parameters:
node - Node
nodeName - String
Returns:
Node

getChildByName

public static org.w3c.dom.Node getChildByName(org.w3c.dom.Node node,
                                              java.lang.String nodeName)
Find node by name.

Parameters:
node - Node
nodeName - String
Returns:
Node

getChildStringByName

public static java.lang.String getChildStringByName(org.w3c.dom.Node node,
                                                    java.lang.String nodeName,
                                                    java.lang.String errValue)
Parameters:
node - Node
nodeName - String
errValue - String
Returns:
String

getChildIntegerByName

public static int getChildIntegerByName(org.w3c.dom.Node node,
                                        java.lang.String nodeName,
                                        int errValue)
Parameters:
node - Node
nodeName - String
errValue - int
Returns:
int

getChildBooleanByName

public static boolean getChildBooleanByName(org.w3c.dom.Node node,
                                            java.lang.String nodeName)
"1" means true. Otherwise false.

Parameters:
node - Node
nodeName - String
Returns:
boolean

getChildDoubleByName

public static double getChildDoubleByName(org.w3c.dom.Node node,
                                          java.lang.String nodeName,
                                          double errValue)
Parameters:
node - Node
nodeName - String
errValue - double
Returns:
double

xslTransform

public static java.lang.String xslTransform(org.w3c.dom.Document xmlDoc,
                                            org.w3c.dom.Document xslDoc)
                                     throws javax.xml.transform.TransformerConfigurationException,
                                            javax.xml.transform.TransformerException
Performs XSL transformation.

Parameters:
xmlDoc - Document
xslDoc - Document
Returns:
String The output text.
Throws:
javax.xml.transform.TransformerConfigurationException
javax.xml.transform.TransformerException

findAttribute

public static org.w3c.dom.Node findAttribute(org.w3c.dom.Node node,
                                             java.lang.String name)
Finds attribute of node by name.

Parameters:
node - Node The context node.
name - String
Returns:
Node

getAttributeString

public static java.lang.String getAttributeString(org.w3c.dom.Node node,
                                                  java.lang.String name)
Gets the value of a named attribute of a node.

Parameters:
node - Node The context node.
name - String
Returns:
String null means node is not found.

getAttributeInteger

public static int getAttributeInteger(org.w3c.dom.Node node,
                                      java.lang.String name,
                                      int errValue)
Gets the integer value of a named attribute of a node.

Parameters:
node - Node The context node.
name - String
errValue - int
Returns:
int

getAttributeDouble

public static double getAttributeDouble(org.w3c.dom.Node node,
                                        java.lang.String name,
                                        double errValue)
Gets the double value of a named attribute of a node.

Parameters:
node - Node The context node.
name - String
errValue - double
Returns:
double

getAttributeBoolean

public static boolean getAttributeBoolean(org.w3c.dom.Node node,
                                          java.lang.String name)
Gets the boolean value of a named attribute of a node.

Parameters:
node - Node
name - String
Returns:
boolean

setChildValue

public static void setChildValue(org.w3c.dom.Document doc,
                                 org.w3c.dom.Node parent,
                                 java.lang.String childName,
                                 java.lang.String value)
Parameters:
doc - Document
parent - Node
childName - String
value - String

setChildValue

public static void setChildValue(org.w3c.dom.Document doc,
                                 org.w3c.dom.Node parent,
                                 java.lang.String childName,
                                 int value)
Parameters:
doc - Document
parent - Node
childName - String
value - int

saveDomToFile

public static void saveDomToFile(org.w3c.dom.Document doc,
                                 java.lang.String filePath)
                          throws java.lang.Exception
Save content of DOM to a file.

Parameters:
doc - Document
filePath - String
Throws:
java.lang.Exception

Changes since
the last release

The information contained in this document is proprietary and confidential. Use of this information and the eBay API requires a Non-Disclosure Agreement (NDA) between the user and eBay Inc. For information regarding a qualifying NDA, contact Developer Relations: developer-relations@ebay.com
© 2004-2009 eBay Inc. All rights reserved.