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 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(Element parent, String name, int value)
           
static void appendAttributeNode(Element parent, String name, String value)
           
static void appendAttributeNode(String namespace, Element parent, String name, int value)
           
static void appendAttributeNode(String namespace, Element parent, String name, String value)
           
static Element appendChildNode(Document doc, Node parent, String name)
           
static Element appendChildNode(Document doc, Node parent, String name, int value)
           
static Element appendChildNode(Document doc, Node parent, String name, String value)
           
static Element appendChildNode(Document doc, String namespace, Node parent, String name)
           
static Element appendChildNode(Document doc, String namespace, Node parent, String name, String value)
           
static Element appendChildNodeCDATA(Document doc, Node parent, String name, int value)
           
static Element appendChildNodeCDATA(Document doc, Node parent, String name, String value)
           
static Document createDom()
           
static Document createDom(File file)
          Method to create a DOM document tree from a file
static Document createDom(InputStream is)
          Method to create a DOM document tree from a InputStream
static Document createDom(String xml)
          Method to create a DOM document tree from a valid XML string
static Document createDomByPathname(String pathname)
          Method to create a DOM document tree from a fuke
static Node findAttribute(Node node, String name)
          Finds attribute of node by name.
static Node findNode(Node node, String nodeName)
          Find node by name recursively.
static boolean getAttributeBoolean(Node node, String name)
          Gets the boolean value of a named attribute of a node.
static double getAttributeDouble(Node node, String name, double errValue)
          Gets the double value of a named attribute of a node.
static int getAttributeInteger(Node node, String name, int errValue)
          Gets the integer value of a named attribute of a node.
static String getAttributeString(Node node, String name)
          Gets the value of a named attribute of a node.
static boolean getChildBoolean(Node node, String xpath)
           
static boolean getChildBooleanByName(Node node, String nodeName)
          "1" means true.
static Node getChildByName(Node node, String nodeName)
          Find node by name.
static Date getChildDate(Node node, String xpath)
           
static double getChildDouble(Node node, String xpath)
           
static double getChildDoubleByName(Node node, String nodeName, double errValue)
           
static int getChildInteger(Node node, String xpath)
           
static int getChildIntegerByName(Node node, String nodeName, int errValue)
           
static String getChildString(Node node, String xpath)
           
static String getChildStringByName(Node node, String nodeName, String errValue)
           
static String getChildStringNS(Element element, String namespace, String childName)
           
static String getXmlStringFromDom(Document doc)
          Method to get formatted Xml string from Xml document
static String getXmlStringFromSource(Source payload)
          Method to get formatted Xml string from Xml source
static void saveDomToFile(Document doc, String filePath)
          Save content of DOM to a file.
static void setChildValue(Document doc, Node parent, String childName, int value)
           
static void setChildValue(Document doc, Node parent, String childName, String value)
           
static String xslTransform(Document xmlDoc, 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 String getXmlStringFromSource(Source payload)
Method to get formatted Xml string from Xml source

Parameters:
payload - Source
Returns:
a formatted Xml string

getXmlStringFromDom

public static String getXmlStringFromDom(Document doc)
Method to get formatted Xml string from Xml document

Parameters:
doc -
Returns:
a formatted Xml string

createDom

public static Document createDom(String xml)
                          throws SAXException,
                                 IOException,
                                 ParserConfigurationException
Method to create a DOM document tree from a valid XML string

Parameters:
xml - String
Returns:
An org.w3c.dom.Document object
Throws:
SAXException
IOException
ParserConfigurationException

createDom

public static Document createDom()
                          throws SAXException,
                                 IOException,
                                 ParserConfigurationException
Returns:
Document
Throws:
SAXException
IOException
ParserConfigurationException

createDom

public static Document createDom(File file)
                          throws SAXException,
                                 IOException,
                                 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:
SAXException
IOException
ParserConfigurationException

createDom

public static Document createDom(InputStream is)
                          throws SAXException,
                                 IOException,
                                 ParserConfigurationException
Method to create a DOM document tree from a InputStream

Parameters:
is - InputStream
Returns:
An org.w3c.dom.Document object
Throws:
SAXException
IOException
ParserConfigurationException

createDomByPathname

public static Document createDomByPathname(String pathname)
                                    throws SAXException,
                                           IOException,
                                           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:
SAXException
IOException
ParserConfigurationException

appendChildNode

public static Element appendChildNode(Document doc,
                                      Node parent,
                                      String name)
Parameters:
doc - Document
parent - Node
name - String
Returns:
Element

appendChildNode

public static Element appendChildNode(Document doc,
                                      String namespace,
                                      Node parent,
                                      String name)
Parameters:
doc - Document
namespace - String
parent - Node
name - String
Returns:
Element

appendChildNode

public static Element appendChildNode(Document doc,
                                      Node parent,
                                      String name,
                                      int value)
Parameters:
doc - Document
parent - Node
name - String
value - int
Returns:
Element

appendChildNode

public static Element appendChildNode(Document doc,
                                      Node parent,
                                      String name,
                                      String value)
Parameters:
doc - Document
parent - Node
name - String
value - String
Returns:
Element

appendChildNode

public static Element appendChildNode(Document doc,
                                      String namespace,
                                      Node parent,
                                      String name,
                                      String value)
Parameters:
doc - Document
namespace - String
parent - Node
name - String
value - String
Returns:
Element

appendAttributeNode

public static void appendAttributeNode(Element parent,
                                       String name,
                                       String value)
Parameters:
parent - Element
name - String
value - String

appendAttributeNode

public static void appendAttributeNode(String namespace,
                                       Element parent,
                                       String name,
                                       String value)
Parameters:
namespace - String
parent - Element
name - String
value - String

appendAttributeNode

public static void appendAttributeNode(Element parent,
                                       String name,
                                       int value)
Parameters:
parent - Element
name - String
value - int

appendAttributeNode

public static void appendAttributeNode(String namespace,
                                       Element parent,
                                       String name,
                                       int value)
Parameters:
namespace - String
parent - Element
name - String
value - int

appendChildNodeCDATA

public static Element appendChildNodeCDATA(Document doc,
                                           Node parent,
                                           String name,
                                           int value)
Parameters:
doc - Document
parent - Node
name - String
value - int
Returns:
Element

appendChildNodeCDATA

public static Element appendChildNodeCDATA(Document doc,
                                           Node parent,
                                           String name,
                                           String value)
Parameters:
doc - Document
parent - Node
name - String
value - String
Returns:
Element

getChildString

public static String getChildString(Node node,
                                    String xpath)
                             throws TransformerException
Parameters:
node - Node
xpath - String
Returns:
String
Throws:
TransformerException

getChildStringNS

public static String getChildStringNS(Element element,
                                      String namespace,
                                      String childName)
Parameters:
element - Element
namespace - String
childName - String
Returns:
String

getChildInteger

public static int getChildInteger(Node node,
                                  String xpath)
                           throws TransformerException
Parameters:
node - Node
xpath - String
Returns:
int
Throws:
TransformerException

getChildBoolean

public static boolean getChildBoolean(Node node,
                                      String xpath)
                               throws TransformerException
Parameters:
node - Node
xpath - String
Returns:
boolean
Throws:
TransformerException

getChildDouble

public static double getChildDouble(Node node,
                                    String xpath)
                             throws TransformerException
Parameters:
node - Node
xpath - String
Returns:
double
Throws:
TransformerException

getChildDate

public static Date getChildDate(Node node,
                                String xpath)
                         throws TransformerException,
                                ParseException
Parameters:
node - Node
xpath - String
Returns:
Date
Throws:
TransformerException
ParseException

findNode

public static Node findNode(Node node,
                            String nodeName)
Find node by name recursively.

Parameters:
node - Node
nodeName - String
Returns:
Node

getChildByName

public static Node getChildByName(Node node,
                                  String nodeName)
Find node by name.

Parameters:
node - Node
nodeName - String
Returns:
Node

getChildStringByName

public static String getChildStringByName(Node node,
                                          String nodeName,
                                          String errValue)
Parameters:
node - Node
nodeName - String
errValue - String
Returns:
String

getChildIntegerByName

public static int getChildIntegerByName(Node node,
                                        String nodeName,
                                        int errValue)
Parameters:
node - Node
nodeName - String
errValue - int
Returns:
int

getChildBooleanByName

public static boolean getChildBooleanByName(Node node,
                                            String nodeName)
"1" means true. Otherwise false.

Parameters:
node - Node
nodeName - String
Returns:
boolean

getChildDoubleByName

public static double getChildDoubleByName(Node node,
                                          String nodeName,
                                          double errValue)
Parameters:
node - Node
nodeName - String
errValue - double
Returns:
double

xslTransform

public static String xslTransform(Document xmlDoc,
                                  Document xslDoc)
                           throws TransformerConfigurationException,
                                  TransformerException
Performs XSL transformation.

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

findAttribute

public static Node findAttribute(Node node,
                                 String name)
Finds attribute of node by name.

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

getAttributeString

public static String getAttributeString(Node node,
                                        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(Node node,
                                      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(Node node,
                                        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(Node node,
                                          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(Document doc,
                                 Node parent,
                                 String childName,
                                 String value)
Parameters:
doc - Document
parent - Node
childName - String
value - String

setChildValue

public static void setChildValue(Document doc,
                                 Node parent,
                                 String childName,
                                 int value)
Parameters:
doc - Document
parent - Node
childName - String
value - int

saveDomToFile

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

Parameters:
doc - Document
filePath - String
Throws:
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.