Creating XML child elements

I'm generating an XML document. I have reached the third hierarchial level i.e.
<level_1>
. <level_2>
. . <level_3>
. <level_2>
. . <level_3>
. <level_2>
<level_1>
Now I am trying to add <level_3> siblings to the existing <level_3> elements and am getting the following exception messages:
com.ibm.xml.parser.TXDOMException: com.ibm.xml.parser.TXNodeList#insert(): Wrong
index: 1
at com.ibm.xml.parser.TXNodeList.insert(TXNodeList.java)
at com.ibm.xml.parser.Parent.realInsert(Parent.java)
at com.ibm.xml.parser.Parent.insert(Parent.java)
at com.ibm.xml.parser.Parent.appendChild(Parent.java)
at Convertor.processNodeRecursively(Convertor.java:302)
at Convertor.processNodeRecursively(Convertor.java:320)
at Convertor.main(Convertor.java:86)
What does this mean and how do I correct this so I can continue creating elements at <level_3> of the XML doc.

Hey Jonny99,
When building a XML document, you have to start at the "lowest" level! If you want an element without any children, it has to be a node. This node you can "append" to an element and so on...
If it still doesn't work, you could post your code, I'll be happy to take a look at it!!!
ps I'm working with xml documents too and having some problems with parsing a received string. Please take a look at my topic
"java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8 sequence."
Greetings Jenny
[email protected]

Similar Messages

  • Help on creating and deleting xml child elements using Toplink please.

    Hi there,
    I am trying to build a toplink xml demo illustrating toplink acting as the layer between my java code and an xml datasource.
    After pulling my custom schema into toplink and following the steps in http://www.oracle.com/technology/products/ias/toplink/preview/10.1.3dp3/howto/jaxb/index.htm related to
    Click on Mapping Workbench Project...Click on From XML Schema (JAXB)...
    I am able to set up java code which can run get and sets against my xml datasource. However, I want to also be able create and delete elements within the xml data for child elements.
    i.e. in a simple scenario I have a xsd for departments which has an unbounded element of type employee. How does toplink allow me to add and or remove employees in a department on the marshalled xml data source? Only gets and sets for the elements seem accessible.
    In my experience with database schema based toplink demos I have seen methods such as:
    public void setEmployeesCollection(Collection EmployeesCollection) {
         this.employeesCollection = employeesCollection;
    Is this functionality available for xml backended toplink projects?
    cheers
    Nick

    Hi Nick,
    Below I'll give an example of using the generated JAXB object model to remove and add a new node. The available APIs are defined in the JAXB spec. TopLink also supports mapping your own objects to XML, your own objects could contain more convenient APIs for adding or removing collection members
    Example Schema
    The following XML Schema will be used to generate a JAXB model.
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
         elementFormDefault="qualified" attributeFormDefault="unqualified">
         <xs:element name="department">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element ref="employee" maxOccurs="unbounded"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <xs:element name="employee">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="name" type="xs:string"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
    </xs:schema>---
    Example Input
    The following document will be used as input. For the purpose of this example this XML document is saved in a file called "employee-data.xml".
    <department>
         <employee>
              <name>Anne</name>
         </employee>
         <employee>
              <name>Bob</name>
         </employee>
    </department>---
    Example Code
    The following code demonstrates how to use the JAXB APIs to remove the object representing the first employee node, and to add a new Employee (with name = "Carol").
    JAXBContext jaxbContext = JAXBContext.newInstance("your_context_path");
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    File file = new File("employee-data.xml");
    Department department = (Department) unmarshaller.unmarshal(file);
    // Remove the first employee in the list
    department.getEmployee().remove(0);
    // Add a new employee
    ObjectFactory objectFactory = new ObjectFactory();
    Employee newEmployee = objectFactory.createEmployee();
    newEmployee.setName("Carol");
    department.getEmployee().add(newEmployee);
    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    marshaller.marshal(department, System.out);---
    Example Output
    The following is the result of running the example code.
    <department>
         <employee>
              <name>Bob</name>
         </employee>
         <employee>
              <name>Carol</name>
         </employee>
    </department>

  • Getting XML child elements

    Dear Indesign scripters,
    This script is making from all the XML tags ParagraphStyles.
    But it refuses to take the child elements. Do I have to use XPath expression? And how?
    function main() { 
      var xes, n, doc, ps, xe; 
      if ( !app.documents.length ) return; 
      doc = app.activeDocument;
      xes = doc.xmlElements[0].xmlElements; 
      n = xes.length; 
      while ( n-- ) { 
      xe = xes[n];
      st = doc.paragraphStyles.itemByName (xe.markupTag.name ); 
      !st.isValid && doc.paragraphStyles.add({name:xe.markupTag.name}); 
    main();
    The XML
    <Workbook> 
         <Element_A_01> 
              <Element_A_01></Element_A_01> 
         </Element_A_01> 
         <Element_B_02> 
              <Element_B_02></Element_B_02> 
         </Element_B_02> 
    </Workbook>
    Greetings from Holland

    The code creates two paragraph styles namely Element_A_01 and Element_B_02. These two are created for the immediate child nodes of the Workbook node. Now it seems that you are trying to create pstyles for all the nodes in the XML, which in your case would still be these two as Element_A_01 has a child node that is also named Element_A_01 and the same is the case for Element_B_02.
    If i get your point right then you need to create 4 pstyles if all the nodes have different names, but that is not working. For this you will have to recursively traverse each node that you get from the code xes[n].
    The code be something like this
    function main() {   
      var xes, n, doc, ps, xe;   
      if ( !app.documents.length ) return;   
      doc = app.activeDocument; 
      xes = doc.xmlElements[0].xmlElements; //This gives the immediate child nodes of the Workbook node, hence the length in the next statement is 2  
      n = xes.length;   
      while ( n-- ) {   
      xe = xes[n];   //Here you need to recursively traverse the node xe
      //The no of child elements of xe can be obtained as xe.xmlElements.length
      //First element can be obtained by xe.xmlElements[0]
    main();
    Hope this solves the issue

  • Silent Config: How do I create a child element

    Hello,
    I want to now how to refer to a child element of a new created object. The I want
    to be able to set some of the parameters of the child object:
    i.e.
    create Server "myserver" as s1;
    create Server.WebServer "myserver.mywebserver" as ws1; (???)
    How is this done?? Is it mandatory that I previously define the child element
    in the template or I can create it on the fly.
    Regards
    Cristina

    Cristina,
    Did you manage to solve this issue? I am facing the same situation.
    Best,
    Oscar

  • Com.bea.xml.XmlException error for "could not create child element"

    In Workshop 9.2, after I created a project with XMLBeans Builder Builder against the xsd's and created a web service control against a wsdl, I inserted the control in a client project for consumption. However, when calling into a method of the control, I got a com.bea.xml.XmlException, saying "could not create child element" for an object parameter passed in the call to the method. The relevant info in the server console looks like this:
    Caused by: com.bea.xml.XmlException: could not create child element 'wirelessPhoneNumber' for Wrapped XMLBean operation on '<?xml version="1.0" encoding="UTF-8
    "?><m:sendSMSMessage xmlns:m="http://service.xyz.com/provider/mobile/abc/sendSMSMessage/200701/"><ns:behaviorVersion xmlns:ns="http://service.xyz.com/entity/message/2003/">0</ns:behaviorVersion><ns:custNbr xmlns:ns="http
    ://service.xyz.com/entity/party/2003/">Hello</ns:custNbr></m:sendSMSMessage>'
    Does any have an idea what this is trying to tell me?
    Thanks in advance for any help,
    Jason

    Looking into it further, I think it's the parameter wirelessPhoneNumber, which is a complex type from xsd and a java object passed to the call sendSMSMessage, that is having a namespace problem, or other problem.
    This parameter object was from XMLBeans java binding. I created and set it up like this before passing it to the call:
    PhoneNumberType phoneNumberType = phoneNumberType.Factory.newInstance();
    phoneNumberType.setFormat(PhoneNumberFormatEnum.FREEFORM);
    phoneNumberType.setFullNumber(phoneNumber);
    Obviously, com.bea.xbeanmarshal.buildtime.internal.util.XmlBeanUtil.createWrappedXBeanTopElement of XmlBeanUtil.java had a problem creating a wrapper element for it.
    Any clue from anyone?
    Jason

  • Org.xml.sax.SAXException:SimpleDeserializer encountered a child element..

    Hi All,
    I created a following program using "GetReportDefintion" method provided by BI Publisher Web Services
    package bip_webservices;
    import com.oracle.xmlns.oxp.service.PublicReportService.ItemData;
    import com.oracle.xmlns.oxp.service.PublicReportService.ReportRequest;
    import com.oracle.xmlns.oxp.service.PublicReportService.ReportResponse;
    import com.oracle.xmlns.oxp.service.PublicReportService.ParamNameValue;
    import com.oracle.xmlns.oxp.service.PublicReportService.ReportDefinition;
    import com.oracle.xmlns.oxp.service.PublicReportService.ScheduleRequest;
    import com.oracle.xmlns.oxp.service.PublicReportService.DeliveryRequest;
    import com.oracle.xmlns.oxp.service.PublicReportService.EMailDeliveryOption;
    import  java.io.FileOutputStream;
    import  java.io.OutputStream;
    import java.net.MalformedURLException;
    import java.rmi.RemoteException;
    import  java.util.Calendar;
    import javax.xml.rpc.ServiceException;
    import org.apache.axis.client.Call;
    import org.apache.axis.client.Service;
    import org.apache.axis.encoding.XMLType;
    import org.apache.axis.encoding.ser.BeanDeserializerFactory;
    import org.apache.axis.encoding.ser.BeanSerializerFactory;
    import  javax.xml.namespace.QName;
    import  javax.xml.rpc.ParameterMode;
    import  java.net.URL;
    public class BIP_GetReportDefinition {
        public static void main(String[] args) throws ServiceException, MalformedURLException, RemoteException{
         try{
            final String bipEndpoint = "http://localhost:9704/xmlpserver/services/PublicReportService?wsdl";
            final String bipNamespace = "http://xmlns.oracle.com/oxp/service/PublicReportService";
            final String xdofile = "/MyReports/SummaryCustomerReport/SummaryCustomerReport.xdo";
            Service service = new Service();
            Call call = (Call) service.createCall();
            call.setTargetEndpointAddress(new URL(bipEndpoint));
           System.out.println("BEGIN TESTING getReportDefinition");
            // register the ReportDefinition class
            QName reportDef = new QName(bipNamespace, "ReportDefinition");
            call.registerTypeMapping(ReportDefinition.class, reportDef,
                            BeanSerializerFactory.class, BeanDeserializerFactory.class);
            // register the ParamNameValue class
            QName nmvals = new QName(bipNamespace, "ParamNameValue");
            call.registerTypeMapping(ParamNameValue.class, nmvals, BeanSerializerFactory.class, BeanDeserializerFactory.class);
            call.setOperationName(new QName(bipNamespace, "getReportDefinition"));
            call.addParameter("reportAbsolutePath", XMLType.XSD_STRING, ParameterMode.IN);
            call.addParameter("userID", XMLType.XSD_STRING, ParameterMode.IN);
            call.addParameter("password", XMLType.XSD_STRING, ParameterMode.IN);
            call.setReturnClass(ReportDefinition.class);
            // issue the request
            ReportDefinition reportDefn = (ReportDefinition) call.invoke(
                new Object[] { xdofile, "Administrator", "Administrator"});
            System.out.println("Report Definition Returns with \n Default Output Format = " + reportDefn.getDefaultOutputFormat());
            ParamNameValue params [] = reportDefn.getReportParameterNameValues();
            if (params != null) {
                for (int i = 0; i < params.length; i++) {
                    System.out.print("Parameter " + params.getName() + ":");
    if (params[i].getValues() != null) {
    for (int j = 0; j < params[i].getValues().length; j++)
    System.out.print(" " + params[i].getValues()[j]);
    } else
    System.out.print(" null");
    System.out.println(" - multiple values? " + params[i].isMultiValuesAllowed());
    System.out.println("END TESTING getReportDefinition");
    }catch(Exception e){
    e.printStackTrace();
    I am getting following exception message. Anyone has any ideas what could be the mistake ?
    SEVERE: Exception:
    org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
            at org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(SimpleDeserializer.java:145)
            at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
            at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
            at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
            at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
            at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
            at org.apache.axis.client.Call.invoke(Call.java:2467)
            at org.apache.axis.client.Call.invoke(Call.java:2366)
            at org.apache.axis.client.Call.invoke(Call.java:1812)
            at bip_webservices.BIP_GetReportDefinition.main(BIP_GetReportDefinition.java:67)
    AxisFault
    faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
    faultSubcode:
    faultString: org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
    faultActor:
    faultNode:
    faultDetail:
            {http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
            at org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(SimpleDeserializer.java:145)
            at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
            at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
            at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
            at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
            at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
            at org.apache.axis.client.Call.invoke(Call.java:2467)
            at org.apache.axis.client.Call.invoke(Call.java:2366)
            at org.apache.axis.client.Call.invoke(Call.java:1812)
            at bip_webservices.BIP_GetReportDefinition.main(BIP_GetReportDefinition.java:67)
            {http://xml.apache.org/axis/}hostname:mildh0228
    org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
            at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
            at org.apache.axis.client.Call.invoke(Call.java:2470)
            at org.apache.axis.client.Call.invoke(Call.java:2366)
            at org.apache.axis.client.Call.invoke(Call.java:1812)
            at bip_webservices.BIP_GetReportDefinition.main(BIP_GetReportDefinition.java:67)
    Caused by: org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
            at org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(SimpleDeserializer.java:145)
            at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
            at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
            at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
            at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
            at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
            at org.apache.axis.client.Call.invoke(Call.java:2467)
            ... 3 moreThanks for giving this problem a look.
    -Sookie

    Hi Sookie,
    I found the problem is with couple of child parameters are not registered the deserializer. There're couple of additional classes needs to be registerd.
    // register the TemplateLabelValue class
    QName templateval = new QName(bipNamespace, "TemplateFormatLabelValue");
    Class cls = TemplateFormatLabelValue.class;
    call.registerTypeMapping(cls, templateval, BeanSerializerFactory.class, BeanDeserializerFactory.class);
    // register the TemplateLabelValues class
    QName templatevals = new QName(bipNamespace, "TemplateFormatsLabelValues");
    cls = TemplateFormatsLabelValues.class;
    call.registerTypeMapping(cls, templatevals, BeanSerializerFactory.class, BeanDeserializerFactory.class);
    Could you please give it a try?
    Thanks.
    Yang

  • Un-nest XML with single child element

    I'm trying to write a generic function for un-nesting child nodes where nesting is deemed unnecessary. Typically when the element only has one child element.
    For example, given the following source....
    <ROOT>
      <ITEM>
        <DESCRIPTION>TEST1</DESCRIPTION>
      </ITEM>
      <ITEM>
        <DESCRIPTION>TEST2</DESCRIPTION>
      </ITEM>
    </ROOT>I actually want.....
    <ROOT>
      <DESCRIPTION>TEST1</DESCRIPTION>
      <DESCRIPTION>TEST2</DESCRIPTION>
    </ROOT>because we think ITEM isn't really required before we deliver XML data.
    I've been trying to achieve this with a function, where I pass in the XPath to the node I want flattening, something like
    function UnNest(pXMLData XMLType, pXPath varchar2) return XMLType...Called like the following...
    declare
    begin
      vXMLData := UnNest(SomeXMLData, '/ROOT/ITEM')
    end;I tried using XQuery Update (11gR2), as follows,
    select /*+ no_xml_query_rewrite */
      xmlquery('
        copy $d := .
         modify (
            for $i in $d/ROOT/ITEM
            return
              replace node $i with $i/child::node()  
         return $d'
      passing xmltype(
    '<ROOT>
      <ITEM>
        <DESCRIPTION>TEST1</DESCRIPTION>
      </ITEM>
      <ITEM>
        <DESCRIPTION>TEST2</DESCRIPTION>
      </ITEM>
    </ROOT>'
      returning content) XML
    from dual.... which works, but when I try to pass in a path variable, it doesn't.
    select /*+ no_xml_query_rewrite */
      xmlquery('
        copy $d := .
         modify (
            for $i in $d/$Unnestpath
            return
              replace node $i with $i/child::node()  
         return $d'
      passing xmltype(
    '<ROOT>
      <ITEM>
        <DESCRIPTION>TEST1</DESCRIPTION>
      </ITEM>
      <ITEM>
        <DESCRIPTION>TEST2</DESCRIPTION>
      </ITEM>
    </ROOT>'
      'ROWSET/ROW' as "Unnestpath"
      returning content) XML
    from dual
    ORA-19112: error raised during evaluation:
    XVM-01020: [XPTY0020] The path step context item is not a node
    6             replace node $i with $i/child::node()  
    -                                   ^Am I missing something obvious?
    My destination platform is 11gR2 64 bit but going forward I may need a solution for 10gR2 too. Perhaps there is another way without using XQuery Update? Any advice would be greatly appreciated.

    paul zip wrote:
    when I try to pass in a path variable, it doesn't.Yes, paths are not variables, they have to be static. However, you can make the whole query dynamic.
    Another option is XSLT, which will work on both releases, or a combination of extract/updatexml calls.
    SQL> create or replace function UnNest(pXMLData XMLType, pXPath varchar2)
      2  return XMLType
      3  is
      4    result          XMLType;
      5    xsl_template    varchar2(2000) :=
      6    '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      7    <xsl:template match="@*|node()">
      8      <xsl:copy>
      9        <xsl:apply-templates select="@*|node()"/>
    10      </xsl:copy>
    11    </xsl:template>
    12    <xsl:template match="#TARGET_XPATH#">
    13      <xsl:apply-templates select="node()"/>
    14    </xsl:template>
    15  </xsl:stylesheet>';
    16 
    17  begin
    18 
    19    select xmltransform(
    20             pXMLData
    21           , xmlparse(document replace(xsl_template, '#TARGET_XPATH#', pXPath))
    22           )
    23    into result
    24    from dual ;
    25 
    26    return result;
    27 
    28  end;
    29  /
    Function created
    SQL> set long 5000
    SQL>
    SQL> select unnest(
      2  xmltype(
      3  '<ROOT>
      4    <ITEM>
      5      <DESCRIPTION>TEST1</DESCRIPTION>
      6    </ITEM>
      7    <ITEM>
      8      <DESCRIPTION>TEST2</DESCRIPTION>
      9    </ITEM>
    10  </ROOT>'),
    11  '/ROOT/ITEM'
    12  )
    13  from dual;
    UNNEST(XMLTYPE('<ROOT><ITEM><D
    <ROOT>
    <DESCRIPTION>TEST1</DESCRIPTION>
    <DESCRIPTION>TEST2</DESCRIPTION>
    </ROOT>
    Typically when the element only has one child element.If it's a general rule to apply, XSLT can do it very easily on every node that satisfies this condition.
    Edited by: odie_63 on 21 mai 2013 12:38

  • Dynamically rename the root node of XML based on the child elements

    Hi Gurus,
    Is there any way to rename the root node of the resultant XML after a mapping based on the child elements.
    For ex:
    consider the following resultant XML after mapping
    <result>
    <element1> </element1>
    <result>
    if the element1 is <type> then the output should be
    <category>
    <type> </type>
    </category>
    elseif the element1 is <character> then the output should be
    <property>
    <character> </character>
    </property>
    Let me know how to do this, either in XSLT or in Graphical mapping.
    Thanks,
    Prabu

    Hi, Prabu:
    In this case, I am suggest you have Src and Tar Message.
    I am suggesting you create another type of message using key / value pair as I suggested, e.g. called Mid Message.
    My solution for you is to have two message mappings:
    1. Src -> Mid
    2. Mid -> Tar.
    In first mapping, you have no control of the structure, but you can map it to Mid structure:
    e.g.
      if Type node Exist, then map 'Type' to Key, as Key/Value can be creatd under a parent node with 0:1 Occurrence.
      saying item.
       in this case, a new item created.
    If you think of this way, any xml file can be represted in this way:
       <Employee>
          <Fname>David</Fname>
          <Lname>Miller</Lname>
       </Employee>  
       <Employee>
          <Fname>Steve</Fname>
          <Lname>Mai</Lname>
       </Employee>   
    Can be interpretd as this way:
       <Employee>
          <Element>
             <key>Fname</Key>
             <value>David</Value>
          </Element>
          <Element>
             <key>Lname</Key>
             <value>Miller</Value>
          </Element>
       </Employee>  
       <Employee>
          <Element>
             <key>Fname</Key>
             <value>Steve</Value>
          </Element>
          <Element>
             <key>Lname</Key>
             <value>Mai</Value>
          </Element>
       </Employee> 
    Now you should understand what I mean.
    In your case target structure have to desgined as following way:
    You need to put Category and Property together with their sub-structure in parallel, make occurence to 0:1
    In your second mapping, you can check the key value is "Type" or "Character", based on which one is true,
    you create corresponding structure: either Categary or Property.
    Regards
    Liang
    Edited by: Liang Ji on Oct 22, 2010 8:31 PM
    Edited by: Liang Ji on Oct 22, 2010 8:35 PM

  • How get all child elements from XML

    Hi
    I have one xml i tried to parse that xml using dom parser and i need to get some child elements using java
    <Group>
    <NAME>ABC</NAME>
    <Age>24</AgeC>
    ---------some data here......
    <Group1>
    <group1Category>
    <NAME>ABCTest</NAME>
    <age>27</Age>
    ----Some data here
    <group1subcategory>
    <subcategory>
    <NAME>ABCDEF</NAME>
    <age>28</Age>
    my intention was
    get group name (here ABC) i need all other name value from group1category ,group1 subcategory but pblm that
    my xml contains any number of Group nodes...but only i want name contains ABC
    i wriiten code like this
    DocumentBuilderFactory factory = DocumentBuilderFactory
    .newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(xmlFile);
    NodeList nodeList = document.getElementsByTagName("*");
    for (int i = 0; i < nodeList.getLength(); i++)
    Element element = (Element) nodeList.item(i);
    what is next step i need to do..please help

    964749 wrote:
    Sorry for inconvenience caused..i only asked if any ideas i not ask any body to spent time for me...
    This is simple code developed using xpath..i not know how i proceed further
    public class Demo {
    public static void main(String[] args) {
    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    try {
    DocumentBuilder builder = domFactory.newDocumentBuilder();
    Document dDoc = builder.parse("hello.xml");
    XPath xpath = XPathFactory.newInstance().newXPath();
    javax.xml.xpath.XPathExpression expr = xpath.compile("//Group/NAME");
    Object Name= expr.evaluate(dDoc, XPathConstants.STRING);
    System.out.println(Name);
    } catch (Exception e) {
    e.printStackTrace();
    i need get group name (here ABC) i need all other name value from group1category ,group1 subcategory but pblm that
    ..how i done in XPATH and also do manipulation of remining result...
    i also try with DOM like
    NodeList nodeList = document.getElementsByTagName("GROUP");
    for (int i = 0; i < nodeList.getLength(); i++)
    Element element = (Element) nodeList.item(i);
    if (element.getNodeName().matches("ECUC-MODULE-DEF"))
    String str=((Element) nodeList.item(i)).getElementsByTagName("NAME").item(0).getFirstChild().getNodeValue();
    if(str.equalsIgnoreCase("abc")){
    NodeList children = element.getChildNodes();
    for (int k = 0; k < children.getLength(); k++) {
    Node child = children.item(k);
    System.out.println("children"+children.getLength());
    if (child.getNodeType() != Node.TEXT_NODE) {
    if(child.getNodeName().equalsIgnoreCase("Group1"))
    how iterate for particular ABC name to group1 and subcategoryFew things
    1. Use code tags to format code
    2. Explain the problem statement clearly. Take time to formulate your question. Explain what you expect from your code and what you are getting along with any exceptions that are being thrown

  • Create XML Element Tag BasedOn Found Character Style

    Hi,
    Good Day!
    Basically I want to search only for character styles that contains "ntb-", that is why it is hard coded in my searchString variable.
    Although I was able to create XML tag based on selected character style, but it will always add/insert at the end of the parent XML element.
    Can anyone could help me how insert/add that element at the insertion point where the text is found?
    Thanks,
    --elmer
    var myDoc = app.documents[0];
    myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.POINTS;
    myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.POINTS;
    var charStyles = myDoc.allCharacterStyles;
    var foundStyles = Array();
    var searchString = String();
        searchString = 'ntb-';
    var tempName = String();
    var tempName1 = String();
    for(var i = 1; charStyles.length > i; i++){
       tempName = charStyles[i].name;
       tempName1 = tempName.toLowerCase();
       if(tempName1.indexOf (searchString.toLowerCase()) != -1){
           foundStyles.push (tempName);
    var myDialog = app.dialogs.add({name: "Convert Footnote Character Styles to XML Tags",canCancel:true});
    with (myDialog) {
        with (dialogColumns.add().borderPanels.add()) {
            with (dialogColumns.add()) {
                staticTexts.add({staticLabel: "Character style to search : "});        }
            with (dialogColumns.add()) {
                selCharStyle = dropdowns.add({stringList: foundStyles, selectedIndex: 0, minWidth: 175});
    var dialogShown = myDialog.show();
    while (dialogShown) {
        if (selCharStyle.selectedIndex == 0) {
            alert("Must have at least a character style to search!");
            dialogShown = myDialog.show();
            continue;
        } else {
            insertXMLTags(selCharStyle.stringList[selCharStyle.selectedIndex], selCharStyle.selectedIndex, "0");
            break;
    myDialog.destroy();
    alert("Finished!");
    exit();
    function insertXMLTags(cStyle, cStyleIndex, ip) {
        var myFinds = searchStyle(cStyle, cStyleIndex);
        for (i=myFinds.length - 1; i>=0; i--) {
            var myIP = myFinds[i].texts.item(0).insertionPoints.item(0);
            var myParentXML = myIP.associatedXMLElements[0];
            var myChiidXML = myParentXML.xmlElements.add ( cStyle );
            myChiidXML.contents =  myFinds[i].contents;
            //set the selection
            app.selection = myFinds[i].texts.item(0);
            //remove the selected text
            myFinds[i].texts.item(0).remove();
            Utility Functions         
    function searchStyle(cStyle, cStyleIndex){
        var myFinds;
        // if script version is for Indesign CS2
        if (app.scriptPreferences.version < 5){                                 
            app.findPreferences = NothingEnum.nothing;
            app.changePreferences = NothingEnum.nothing;
            myFinds = myDoc.search(undefined, undefined, undefined, undefined,
            {appliedParagraphStyle: pStyle, appliedCharacterStyle: cStyle});
        // else, for CS3 and CS4
        }else{                                 
            //Clear any existing find/change settings
            app.findTextPreferences = NothingEnum.nothing;
            app.changeTextPreferences = NothingEnum.nothing;
            // set character or paragraph style to search
            if (cStyleIndex != 0){ 
                app.findTextPreferences.appliedCharacterStyle = cStyle;
            //Set the find options.
            app.findChangeTextOptions.caseSensitive = false;
            app.findChangeTextOptions.includeFootnotes = true;
            app.findChangeTextOptions.includeHiddenLayers = false;
            app.findChangeTextOptions.includeLockedLayersForFind = false;
            app.findChangeTextOptions.includeLockedStoriesForFind = false;
            app.findChangeTextOptions.includeMasterPages = false;
            app.findChangeTextOptions.wholeWord = false;                             
            myFinds = myDoc.findText();
        return myFinds;

    Here is a way you can find any field.
    Download the current template.
    Open it in word and go to the line that you are interested in.
    The blanket PO# will be a field. Right click on it and go to properties. You will see the xml element there.
    Hope this answers your question,
    Sandeep Gandhi

  • XML element,if not including any attributes and/or child elements then

    XML element in SQLX,if not including any attributes and/or child elements then the tag should not appear, how to achive this?
    ex:Consider for <enumeration> tag where it is having some value.
    <attribute>
    <name>Ethernet Access</name>
    <enumeration>
    <StringValue>Bandwidth</StringValue>
    </enumeration>
    </attribute>
    When <enumeration> tag is not have any Value in this, then output should be as follows.
    <attribute>
    <name>Ethernet Access</name>
    </attribute>
    But what i am getting is
    <attribute>
    <name>Ethernet Access</name>
    </enumeration>
    </attribute>
    Please suggest me the solution for this.
    I tried , but when xmlelement() is not having data it will display empty tag ie </enumeration>, If xmlforest() are null it wont show tag, But i have to use xmlelement only. how can that be achived using xmlelement .

    Use a SQL case - when - else end construct to only execute the xmlelement if data is present. The SQL/XML standard is very clear, xmlElement will generate an empty element if no data is present. xmlforest will not.

  • How create Nested Child Nodes in XML Forms

    Hello All:
                        I am very new to XML Forms/KM. I am trying to figure out a way to create Nested Child Nodes schema in XML Forms. Is there a way we can do it?
    Thanks and Regards,
    Vasu.

    Document document;
    NodeList[] dataNodeList=new NodeList[2];
    NodeList nodeList=document.getElementsByTagName("MyData");
    for(int i=0; i<nodeList.getLength(); i++)
    dataNodeList=nodeList.getChildNodes();

  • Create XML element without closing tag using Visual C++

    I know how to create xml element with closing tag (using WriteStartElement and WriteEndElement methods)
    <tag id="1234">
    </tag>
    but is there a way in Visual C++ to produce xml element like this
    <tag id="1234"/>
    i.e. without closing tag?

    Hi adamay,
    Please refer to this thread.
    http://stackoverflow.com/questions/8182245/create-xml-element-without-closing-tag-using-xslt
    I think you could try the way of write your own class derived from XmlWriter.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to get child elements of element in xml?

    public class Test {
         public static void main(String[] args) {
              Document doc = null;
              System.out.println("!!!");
              try {
                   // TODO if path is 'c:' then make it 'c:/'
                   doc=DocumentBuilderFactory.newInstance().newDocumentBuilder().parse("test.xml");
              } catch (Exception e) {
                   System.out.println("exception");
              Element root = doc.getDocumentElement();
              NodeList dsList = root.getElementsByTagName("GenericDataSource");
              Element e = (Element)dsList.item(0);
             NodeList nl = e.getChildNodes();
             System.out.println(nl.getLength());
             Node n  = nl.item(0);
             Element ee = (Element)n;
    }i want to get child elements. but its throwing exception on typecasting. can u tell me why?

    thanks for the info.
    i got 2 solutions
    SOLUTION 1:
    public class Test {
         public static void main(String[] args) throws Exception {
              Document doc = null;
              System.out.println("!!!");
              try {
                   // TODO if path is 'c:' then make it 'c:/'
                   doc=DocumentBuilderFactory.newInstance().newDocumentBuilder().parse("test.xml");
              } catch (Exception e) {
                   System.out.println("exception");
              Element root = doc.getDocumentElement();
              NodeList dsList = root.getElementsByTagName("GenericDataSource");
              Element e = (Element)dsList.item(0);
             NodeList nl = e.getChildNodes();
             int count = 0;
             System.out.println(nl.getLength());
             for(int i=0;i<nl.getLength();i++){
                      Node n  = nl.item(i);
                     //System.out.println(n.getClass().getName()); 
                     //System.out.println((Element)n);
                     if(n instanceof Element){ // this checks for node type
                          count++;
                          System.out.println("Element "+(Element)n);
    SOLUTION 2: :
    XPath xpath  = XPathFactory.newInstance().newXPath();
             InputSource inputSource = new InputSource("test.xml");
             NodeList nodes = (NodeList) xpath.evaluate("//GenericDataSource/*", inputSource, XPathConstants.NODESET);
             System.out.println(nodes.getLength());
             System.out.println((Element)nodes.item(9));

  • Performance problem when creating XML-file

    Hi,
    I want to create a XML-file with customer data from an internal table. This internal table has appr. 62000 entries. It takes hours to create the elements of the file.
    This is the coding I have used:
      loop at it_debtor.
        at first.
        Creating a ixml factory
          l_ixml = cl_ixml=>create( ).
        Creating the dom object model
          l_document = l_ixml->create_document( ).
        Fill root node
          l_element_argdeb  = l_document->create_simple_element(name = 'argDebtors'
                      parent = l_document ).
        endat.
      Create element 'debtor' as child of 'argdeb'
        l_element_debtor  = l_document->create_simple_element(
                     name = 'debtor'
                   parent = l_element_argdeb ).
      Create elements as child of 'debtor'
        l_value = it_debtor-admid.
        perform create_element using 'financialAdministrationId'.
        l_value = it_debtor-kunnr.
        perform create_element using 'financialDebtorId'.
        l_value = it_debtor-name1.
        21 child elements in total are created
      endloop.
      Creating a stream factory
      l_streamfactory = l_ixml->create_stream_factory( ).
      Connect internal XML table to stream factory
      l_ostream = l_streamfactory->create_ostream_itable( table =
      l_xml_table ).
      Rendering the document
      l_renderer = l_ixml->create_renderer( ostream  = l_ostream
                                          document = l_document ).
      l_rc = l_renderer->render( ).
      open dataset p_path for output in binary mode.
      if sy-subrc eq 0.
        loop at l_xml_table into rec.
          transfer rec to p_path.
        endloop.
        close dataset p_path.
        if sy-subrc eq 0.
          write:/ wa_lines, 'records have been processed'.
        endif.
      else.
        write:/ p_path, 'can not be opened.'.
      endif.
    form create_element using    p_text.
      check not l_value is initial.
      l_element_dummy  = l_document->create_simple_element(
                    name = p_text
                    value = l_value
                    parent = l_element_debtor ).
                                                                                    endform.                    " create_element
    Please can anyone tell me how to improve the performance.
    The method create_simple_element takes a long time.
    SAP release : 46C
    Regard,
    Christine

    Hi Christine!
    There might be several reasons - but you have to look at the living patient, not only the dead coding.
    You did not show any selects, loop at ... where or read table statements -> the usual slow parts are not included (or visible...).
    Of course the method-calls can contain slow statements, but you can also have problems because of size (when internal memory gets swaped to disc).
    Make a runtime analysis (SE30), have a look in SM50 (details!) for the size, maybe add an info-message for every 1000-customer (-> will be logged in job-log), so you will see if all 1000-packs are executed in same runtime.
    With this tools you have to search for the slow parts:
    - general out of memory problems, maybe because of to much buffering (visible by slower execution at the end)
    - slow methods / selects / other components by SM30 -> have a closer look
    Maybe a simple solution: make three portions with 20000 entries each and just copy the files into one, if necessary.
    Regards,
    Christian

Maybe you are looking for

  • How to connect two thunderbolt devices to Macbook Air?

    I have been using an Apple thunderbolt to VGA adapter to connect my digital projector to a Macbook Air.  Now I need to also connect a pro audio firewire mixer, which has a firewire 400 cable.  If I didn't have to connect the projector as well, I pres

  • Text frames added to items in my Indesign library?

    Hey, When I put design elements (even just simple text so I can, say, save a headline font I like for a specific element) into my library to re-use later, when I pull them out they have a huge text frame on the, which I then have to remove manually.

  • Help minidlna not updating library

    hey everyone, arch newbie here, having trouble making my dlna work. i can see and access it from my windows boxes but no media shows up. ps i tried changing user to my username but it wouldnt even show up at that point so i commented it out. this is

  • ? in SQL Queries and not using prepared statements

    Using EclipseLink 1.1.1 Prepared Statements are disabled In our production server something went wrong and one of our Read Queries started erroring. A DatabaseException was thrown and we log the "getQuery.getSQLString()" statement. We found this quer

  • Dark curtain descends over MacBook Pro screen

    While I was watching a TV show. Message in several languages said I needed to hold down power button and restart my computer. When I did and the light grey screen appeared, It started emitting a series of thee loud beeps. A small light on the front e