Jaxp namespaces in document elements

I am trying to use Java to access xml items using XPath.
I am OK with an xml document with name spaces in root element.
But not namespaces declared in elements.
Typically see two documents at
http://www.w3schools.com/XML/xml_namespaces.asp
Under
XML Namespaces - The xmlns Attribute
Quote "Namespaces can be declared in the elements where they are used or in the XML root element:"
My Xpath is "/root/h:table/h:tr/h:td"
This works OK for second document with namespaces in root element.
But not the first document with namespaces in the elements.
I have tried using lookupNamespaceURI but this only seems to process root element.
It's hair pulling time!
Any Ideas
Thanks

OK messy but ..
Set the line
XPathDemo xPathDemo = new XPathDemo("C:/opt/XpathDemo/w32.XML");to be either of the two w3schools example quoted previously.
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import javax.xml.XMLConstants;
import javax.xml.namespace.NamespaceContext;
import javax.xml.parsers.DocumentBuilder;  
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class XPathDemo
    public class UniversalNamespaceResolver implements NamespaceContext
        // the delegate
        private Document sourceDocument;
         * This constructor stores the source document to search the namespaces in it.
         * @param document source document
        public UniversalNamespaceResolver(Document document)
            sourceDocument = document;
         * The lookup for the namespace uris is delegated to the stored document.
         * @param prefix to search for
         * @return uri
        public String getNamespaceURI(String prefix)
            String retVal;
            if (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX))
                retVal = sourceDocument.lookupNamespaceURI(null);
            else
                retVal = sourceDocument.lookupNamespaceURI(prefix);
            return retVal;
         * This method is not needed in this context, but can be implemented in a similar way.
        public String getPrefix(String namespaceURI)
            return sourceDocument.lookupPrefix(namespaceURI);
        public Iterator getPrefixes(String namespaceURI)
            // not implemented yet
            return null;
    public XPathDemo(String fileName)
        try
            String dataFileName = "C:/opt/XpathDemo/tmp.txt";
            File f = new File(dataFileName);
            PrintWriter out = new PrintWriter(f);
            generateData(out, fileName);
            out.flush();
            out.close();
        catch (XPathExpressionException xp)
            System.out.println("Exception expression cannot be compiled : " + xp.getMessage());
        catch (NullPointerException np)
            System.out.println("expression is null : " + np.getMessage());
        catch (Exception e)
            System.out.println("General exception : " + e.getMessage());
    public void generateData(PrintWriter out, String fileName) throws ParserConfigurationException, SAXException, IOException,
        XPathExpressionException
        DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
        domFactory.setNamespaceAware(true); // never forget this!
        DocumentBuilder builder = domFactory.newDocumentBuilder();
        Document doc = builder.parse(fileName);
        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();
        xpath.setNamespaceContext(new UniversalNamespaceResolver(doc));
        System.out.println("Setting expr");
        XPathExpression expr = xpath.compile("/root/h:table/h:tr/h:td");
        if (expr != null)
            Object result = expr.evaluate(doc, XPathConstants.NODESET);
            if (result != null)
                NodeList nodes = (NodeList) result;
                System.out.println("Looping through " + nodes.getLength());
                for (int i = 0; i < nodes.getLength(); i++)
                    System.out.println("i = " + i);
                    Node thisNode = nodes.item(i);
                    NodeList thisNode2 = thisNode.getChildNodes();
                    Node xx = thisNode2.item(0);
                    String val = xx.getNodeValue();
                    System.out.println("Value : '" + val + "'");
            else
                System.out.println("Result was NULL");
        else
            System.out.println("Expr was NULL");
    public static void main(String[] args)
        XPathDemo xPathDemo = new XPathDemo("C:/opt/XpathDemo/w32.XML");
        System.out.println("Main complete!");
}

Similar Messages

  • "The stylesheet does not contain a document element" error

    Hi,
    I'm using Hyperion Financial Management 11.1.1.3
    I successfully created intercompany transactions but when I select the "auto match" to perform the matching process, the running task page ensure that the process is completed successfully. However, when I press "log" I found the following error:
    Error Number:-2147467259
    Error Description:The stylesheet does not contain a document element. The stylesheet may be empty, or it may not be a well-formed XML document.
    Error Source:msxml6.dll
    Page On which Error Occurred:/hfm/Administration/ShowRunningTaskLog.asp
    My environment is win server 2003 on a VM and EPM 11.1.1.3
    Thank you and best regards,
    Ahmed.

    Hi taku,
    Yes I've solved my issue.
    Firstly, make sure that the entities and accounts used in the Intercompany Transaction are allowed for ICP in the metadata file by setting the attribute "IsICP=Y" to yes.
    Then, after you press the "Match" button, wait until the process finished and don't open the log. Just close the running task page, after the status showed that it is completed, and open the "process IC transactions" page again you will find the square sign becomes green which means that the transactions are matched.
    I followed the following example on Oracle by Example [http://www.oracle.com/technetwork/middleware/financial-management/tutorials/mictrans-094190.html?ssSourceSiteId=otncn]
    It's about "Managing Intercompany Transactions in Financial Management".
    I wish you can solve your issue soon.
    Best wishes,
    Ahmed.

  • How to remove namespace from root-element

    Hi Gurus,
    I want one xml output from xslt transformation with no namespace. I managed to remove namespace from child elements by leveraging elementFormDefault ='unqualified' property of xsd. But not able remove namespace from root-element.
    Output that I want is :
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <inp1:Email_Mod_Root>
       <Email_Mod_Root_Element>
          <Email_Record1>
             <PERSON_NUMBER>123456</PERSON_NUMBER>
             <COUNTRY/>
              <EMAIL_TYPE>WORK</EMAIL_TYPE>
             <EMAIL>EMAIL3</EMAIL>
             <PRIMARY_FLAG>Y</PRIMARY_FLAG>
          </Email_Record1>
    </Email_Mod_Root_Element>
    </Email_Mod_Root>
    Output that I am getting:
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <inp1:Email_Mod_Root xmlns:inp1="http://www.example.org">
       <Email_Mod_Root_Element>
          <Email_Record1>
             <PERSON_NUMBER>123456</PERSON_NUMBER>
             <COUNTRY/>
             <EMAIL_TYPE>WORK</EMAIL_TYPE>
             <EMAIL>EMAIL3</EMAIL>
             <PRIMARY_FLAG>Y</PRIMARY_FLAG>
          </Email_Record1>
    </Email_Mod_Root_Element>
    </Email_Mod_Root>
    Anyone, pls suggest.
    Thanks in advance,
    SG_SOA

    First of all :
    <inp1:Email_Mod_Root>
       <Email_Mod_Root_Element>
          <Email_Record1>
             <PERSON_NUMBER>123456</PERSON_NUMBER>
             <COUNTRY/>
              <EMAIL_TYPE>WORK</EMAIL_TYPE>
             <EMAIL>EMAIL3</EMAIL>
             <PRIMARY_FLAG>Y</PRIMARY_FLAG>
          </Email_Record1>
    </Email_Mod_Root_Element>
    </Email_Mod_Root>
    isn't valid xml (you start with inp1: prefix and you end the tag with no prefix, but let's assume you don't want any prefix/namespace at all)
    if i use :
    [code]
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:inp1="http://www.example.org" exclude-result-prefixes="inp1">
      <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="*">
        <xsl:element name="{local-name(.)}">
          <xsl:apply-templates select="@* | node()"/>
        </xsl:element>
      </xsl:template>
      <xsl:template match="@*">
        <xsl:attribute name="{local-name(.)}">
          <xsl:value-of select="."/>
        </xsl:attribute>
      </xsl:template>
    </xsl:stylesheet>
    [/code]
    i get this
    [code]
    <Email_Root_Element>
      <Email_Record>
      <EMPLID>EMPLID46</EMPLID>
      <EMAIL>EMAIL48</EMAIL>
      <E_ADDR_TYPE>E_ADDR_TYPE49</E_ADDR_TYPE>
      <COUNTRY>US</COUNTRY>
      </Email_Record>
      <Email_Record>
      <EMPLID>EMPLID47</EMPLID>
      <EMAIL>EMAIL49</EMAIL>
      <E_ADDR_TYPE>E_ADDR_TYPE50</E_ADDR_TYPE>
      <COUNTRY>US</COUNTRY>
      </Email_Record>
      <Email_Record>
      <EMPLID>EMPLID48</EMPLID>
      <EMAIL>EMAIL49</EMAIL>
      <E_ADDR_TYPE>E_ADDR_TYPE51</E_ADDR_TYPE>
      <COUNTRY>US</COUNTRY>
      </Email_Record>
    </Email_Root_Element>
    [/code]

  • Performance of extracting document elements

    I have a container with about 100,000 documents, of which several elements are indexed. When I run a query like this:
    for $lead in doc('dbxml:leads.dbxml/31308')/als:auto-lead-service
    return <lead attempts="{$lead/@processing-attempts}"/>
    the query returns in about 260ms.
    If I change the query to include many more document elements, like this:
    for $lead in doc('dbxml:leads.dbxml/31308')/als:auto-lead-service
    return
    <lead attempts="{$lead/@processing-attempts}"
         lead-date="{$lead/@created}"
         first-name="{$lead/star:SalesLead[1]/star:Header[1]/star:IndividualProspect[1]/star:PersonName[1]/star:GivenName[1]}"
         last-name="{$lead/star:SalesLead[1]/star:Header[1]/star:IndividualProspect[1]/star:PersonName[1]/star:FamilyName[1]}"
         address="{$lead/star:SalesLead[1]/star:Header[1]/star:IndividualProspect[1]/star:Address[1]/star:AddressLine[1]}"
         lead-city="{$lead/star:SalesLead[1]/star:Header[1]/star:IndividualProspect[1]/star:Address[1]/star:City[1]}"
         lead-state="{$lead/star:SalesLead[1]/star:Header[1]/star:IndividualProspect[1]/star:Address[1]/star:StateOrProvince[1]}"
         lead-zip="{$lead/star:SalesLead[1]/star:Header[1]/star:IndividualProspect[1]/star:Address[1]/star:PostalCode[1]}"
         lead-email="{$lead/star:SalesLead[1]/star:Header[1]/star:IndividualProspect[1]/star:Contact[1]/star:EMailAddress[1]}"
         lead-phone="{$lead/star:SalesLead[1]/star:Header[1]/star:IndividualProspect[1]/star:Contact[1]/star:Telephone[1]}"
         lead-source="{$lead/als:id[@source eq 'autoleadservice.com:source']}"
         lead-type="{$lead/als:meta[@key eq 'com.autoleadservice.LeadType']}"
         lead-subtype="{$lead/als:meta[@key eq 'com.autoleadservice.LeadSubType']}"/>
    the query takes about 8 seconds to run.
    Some of these elements are indexed. If I change the query to return only elements that are not indexed, like this:
    for $lead in doc('dbxml:leads.dbxml/31308')/als:auto-lead-service
    return <lead
         first-name="{$lead/star:SalesLead[1]/star:Header[1]/star:IndividualProspect[1]/star:PersonName[1]/star:GivenName[1]}"
         last-name="{$lead/star:SalesLead[1]/star:Header[1]/star:IndividualProspect[1]/star:PersonName[1]/star:FamilyName[1]}"
         address="{$lead/star:SalesLead[1]/star:Header[1]/star:IndividualProspect[1]/star:Address[1]/star:AddressLine[1]}"
         lead-city="{$lead/star:SalesLead[1]/star:Header[1]/star:IndividualProspect[1]/star:Address[1]/star:City[1]}"
         lead-state="{$lead/star:SalesLead[1]/star:Header[1]/star:IndividualProspect[1]/star:Address[1]/star:StateOrProvince[1]}"
         lead-zip="{$lead/star:SalesLead[1]/star:Header[1]/star:IndividualProspect[1]/star:Address[1]/star:PostalCode[1]}"
         lead-email="{$lead/star:SalesLead[1]/star:Header[1]/star:IndividualProspect[1]/star:Contact[1]/star:EMailAddress[1]}"
         lead-phone="{$lead/star:SalesLead[1]/star:Header[1]/star:IndividualProspect[1]/star:Contact[1]/star:Telephone[1]}"
         />
    The query returns in about 260ms again.
    From the query plan when indexed elements are included, it looks like BDB is performing a full index lookup for each indexed element, does that sound correct? Is there a way to force BDB to not use the index?

    Hi Raghu,
    This issue is being handled through Metalink.
    Regards,
    Andrei Costache

  • Can't output text before document element?

    Hello,
    When I try to run my template, which is programmed in Java and which is supposed to extract information from XML-File, I use a XSLTInputSource interface. But the compiler send the following message:
    org.xml.sax.SAXException: Warning: can't output text before document element! Ignoring...
    Can anyone explain me, what this Exception means?
    Thanks
    RudiRatte

    The XML-File is in a database, which I can't access.

  • Parse file without xml specification or document element

    I have a large (600mb) log file that is in xml format but it does not have an xml specification and has no document element.
    file looks like this:
    <message>...</message>
    <message>...</message>
    <!-- ... many many many more <message> elements -->
    <message>...</message>
    <message>...</message>
    I have written a class that overrides the SAX DefaultHandler but now want to be able to parse the document without having to add the xml spec and document element manually.
    I've thought about writing a subclass of FileReader that adds the xml specification and document element before reading physical file but would also need to add closing document element at end of file.
    Is there a simpler way?

    Hi,
    There is another way around the problem of adding a missing root node. This involves adding an extra DTD file and a xml file, like this one:
    <?xml version='1.0' encoding='UTF-8' standalone="no"?>
    <!DOCTYPE messageSet SYSTEM "logfile.dtd"
    [<!ENTITY data SYSTEM "logfile.xml">]
    >
    <messageSet>
    &data;
    </messageSet>
    This file "includes" the logfie.xml, as an external entity, with your messages as child nodes of element messageSet.
    In your program you refer to this xml file when parsing the messages.

  • Junk after document element

    "Junk after document element"—what does that error message mean.
    InCopy (.icml-file) size is 4 MB. We do some minimal text-corrections in InCopy and after check-in the .icml-file-size is 8 MB and the file is defect.
    No help from Adobe support available ! ?
    Thanks Andy

    add, where you want apex to stop generating code,
    apex_application.g_unrecoverable_error := true;example:
    htp.init;
    wwv_flow.g_page_text_generated := true;
    INV_INVOICES_BLOB_DISPLAY(p_image=>:REQUEST);
    apex_application.g_unrecoverable_error := true;had most problems when displaying pure XML, apex added junk in the end of file.

  • How are document elements getting populated.

    I'm trouble-shooting a new Oracle Apex application developed by my predecessor. I see that some variables are being populated by document elements, i.e. var method = document.getElementByID(tlineid).value;
    How are the document elements being populated?
    Some of the places I've looked on the page (Home>Application Builder > Application 147 > Page 4):
    The entire HTML Header;
    All of the regions;
    All of the items;
    The process
    The branch;
    The Lists of Values and
    the Templates.
    Where am I missing?

    Also check the buttons, report column links, application processes (shared components) etc...
    What actions trigger the elements to be populated? Start tracing the events from there.
    Is it a database procedure? Default value, function on the item being populated? or DML automatic fetch on a table database?

  • How to Add namespace to all elements in a xml document

    Hi,
    I am trying to read an xml file that does not have any namespace definitions. I have been able to create another schema in which i specify the namespace defination as shown below.
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://TargetNamespace.com/AckPaymentFile_PL" targetNamespace="http://TargetNamespace.com/AckPaymentFile_PL" xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd" nxsd:version="DTD" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <include schemaLocation="PM_XML_FILE_ACK_SCHEMA_NO_NAMESPACE.xsd"/>
    </xs:schema>
    Once i do it, i am able to see the namespace has been assigned to the root element. I am looking for a way to assign the namespace and prefix tag to all elements in the xml document. If i don't i am unable to access any part of the xml document, keep getting please verify if xpath is correct.
    Thanks
    Sridhar

    Hello,
    Once you've answered all the above.
    If you can run xpath that supports functions against the xml, the expression:
    count(//phone)Otherwise, without leaving SQL:
    select count(*) from
    xmltable('//phone' passing
      -- Your XML goes here, could be a table column with type XMLTYPE.
      xmltype('<person><phone>123-456-7890</phone><phone>098-765-4321</phone></person>')
      columns phone varchar2(24 char) path '/phone'
    ;

  • XPath query on multiple namespace XML document

    Hi,
    I am trying to locate an element in a WordML XML document using XPath.
    The structure looks like:
    <w:body>
         <wx:sect>
              <aml:annotation aml:id="0" w:type="Word.Bookmark.Start" w:name="DOC0000966"/>
    ...So I use the following expression "/wordDocument//body/sect" wich gives me a list with the <w:sect> nodes.
    Then I search for "annotation[@type='Word.Bookmark.Start']" starting from each <w:sect> node. This yields the <aml:annotation> elem.
    So far so good.
    Now I have to handle a second case as well.
    <w:body>
         <wx:sect>
         <w:p>
              <aml:annotation aml:id="0" w:type="Word.Bookmark.Start" w:name="DOC0000966"/>
    ...As you can see the <aml:annotation> is nested inside a <w:p> elem.
    My intention was to use the expression "//annotation[@type='Word.Bookmark.Start']"to handle both cases, but this expression does not match neither.
    I have tried several different alternatives with expressions and NamingContext implementations, none working.
    What am I missing?
    Thanks in advance,
    Mariano.

    Hello,
    I decided to remove all namespaces and prefixes from the XML document and now the expression works.
    I have chaned the following:
    DocumentBuilderFactory is now namespace aware (it isn't by default).
              DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
              builderFactory.setNamespaceAware(true);I picked this NamespaceContext implementation from JAXP 1.4 samples and mapped all prefixes and namespaces coming inside the XML.
              NamespaceContextImpl ns = new NamespaceContextImpl();
              ns.bindPrefixToNamespaceURI("aml", "http://schemas.microsoft.com/aml/2001/core");
              ns.bindPrefixToNamespaceURI("dt", "uuid:C2F41010-65B3-11d1-A29F-00AA00C1488");
              ns.bindPrefixToNamespaceURI("o", "urn:schemas-microsoft-com:office:office");
              ns.bindPrefixToNamespaceURI("sl", "http://schemas.microsoft.com/schemaLibrary/2003/core");
              ns.bindPrefixToNamespaceURI("v", "urn:schemas-microsoft-com:vml");
              ns.bindPrefixToNamespaceURI("w", "http://schemas.microsoft.com/office/word/2003/wordml");
              ns.bindPrefixToNamespaceURI("w10", "urn:schemas-microsoft-com:office:word");
              ns.bindPrefixToNamespaceURI("wx", "http://schemas.microsoft.com/office/word/2003/auxHint");
              XPathFactory xpathFactory = XPathFactory.newInstance();
              XPath xpath = xpathFactory.newXPath();
              xpath.setNamespaceContext(ns);Finally, I prefixed all elements in xpath expressions.
    "//aml:annotation[@w:type='Word.Bookmark.Start']"Happier now,
    Mariano.

  • Getting Namespace From Document Object

    In my JSP I have an Document that contains the contents of an xsl file. I want to search for a specific variable element and then replace its contents with some new value. I think the problem I'm having though relates to namespaces. When calling method selectSingleNode I think I need to pass the namespace node as the 3rd parameter. I'm not sure how to get that though. I know there's a method getNamespaceURI but that returns a string instead of the node. Is there any way to get the namespace node?
    <%
    Document xslDoc = myClass.loadTheXml((new File("test.xsl"))); // assume loadTheXML works correctly
    Node node = XPathAPI.selectSingleNode(xslDoc.getDocumentElement(), "/xsl:stylesheet/xsl:variable[@name='myVariable']");
    %>

    public static Node selectSingleNode(Node contextNode,
                                        java.lang.String str,
                                        Node namespaceNode)The namespaceNode parameter in the selectSingleNode is a Node of the type namespace, for example
    http://exist.sourceforge.net/api/org/exist/memtree/NamespaceNode.html
    http://www.jdocs.org/jaxen/1.0/api/org/jaxen/dom/NamespaceNode.html

  • Several namespaces in root element

    Hi,
    I'm using JDOM and I would like to create an XML document that starts like this:
    <Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-1.0"
    xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-1.0"
    xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-1.0"
    xmlns:ccts="urn:oasis:names:specification:ubl:schema:xsd:CoreComponentParameters-1.0"
    xmlns:cur="urn:oasis:names:specification:ubl:schema:xsd:CurrencyCode-1.0"
    xmlns:sdt="urn:oasis:names:specification:ubl:schema:xsd:SpecializedDatatypes-1.0"
    xmlns:udt="urn:oasis:names:specification:ubl:schema:xsd:UnspecializedDatatypes-1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-1.0 UBL-Invoice-1.0.xsd">
    </Invoice>
    Is there a way to add several namespaces to the root element?? I have tried hard, but nothing works...
    Thank you very much for your help,
    Susana

    OK, it's like dvohra09 said. I had an old copy of jdom.jar and the method addNamespaceDeclaration() didn't exist.
    So, here you have the code to generate the beginning of my file, if ever it's useful to someone as I found it a little bit complicated to find out:
    For this:
    <?xml version="1.0" encoding="UTF-8"?>
    <Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-1.0"
    xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-1.0" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
    xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-1.0 UBL-Invoice-1.0.xsd">
         <ID>serie1_04/00011</ID>
         <cbc:CopyIndicator>false</cbc:CopyIndicator>
    </Invoice>
    The code is:
    Element rootElement = new Element("Invoice", "urn:oasis:names:specification:ubl:schema:xsd:Invoice-1.0");
    rootElement.addNamespaceDeclaration(Namespace.getNamespace("cbc", "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-1.0"));("schemaLocation", "urn:oasis:names:specification:ubl:schema:xsd:Invoice-1.0 UBL-Invoice-1.0.xsd", Namespace.getNamespace("xsi", "http://www.w3.org/2000/10/XMLSchema-instance" ));
    rootElement.setAttribute(schemaLoc);
    Document invoiceDocument = new Document(rootElement);
    // ID          
    rootElement.addContent(new Element("ID", "urn:oasis:names:specification:ubl:schema:xsd:Invoice-1.0").setText(invoice.getId_serie_desc() + "_" + invoice.getNum_factura()));
    // cbc:CopyIndicator     
    rootElement.addContent(new Element("CopyIndicator", "cbc",
    "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-1.0").setText(copyIndicator));
    Thank you for your answers.
    Susana

  • Namespace in xml element

    I have an xml file tagged with namespaces:
    for example, ce:section, ce:para
    i just trying to collect the 'ce:floats' xml nodes by using the following code:
    //Defining the Namespace in the array of arrays of 2 strings
    Dim NmSpArr(,) As String = {{"sb", "http://www.elsevier.com/xml/common/struct-bib/dtd"}, {"cl", "http://xml.cengage-learning.com/cendoc-core"}, {"ce", "http://www.elsevier.com/xml/common/dtd"}, {"aid", "http://ns.adobe.com/AdobeInDesign/4.0/"}, {"aid5", "http://ns.adobe.com/AdobeInDesign/5.0/"}, {"xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"}, {"xmlns:mml", "http://www.w3.org/1998/Math/MathML"}, {"xmlns:xlink", "http://www.w3.org/1999/xlink"}}
    //Trying to collect the 'ce:floats'
    Dim obj As InDesign.Objects = IndDoc.XMLElements(1).EvaluateXPathExpression("//ce:floats", NmSpArr)
    ID CS4
    Vb.net
    Above code always returning 0 as count. It seems there is problem with the xml namespaces definition.
    Any help would be greately appreciated.
    Regards,
    Suresh

    Suresh:
    Is there anyone know any alternative methods to collect the xml nodes with namespaces?
    Again, I wrote:
    But it shouldn't be too much work to just traverse the tree.
    Here's an example in JavaScript. It should be easy to translate it into VB. Of course all you need is the traverse() function -- the rest is just examples and test cases:
    (function() {
      var
        x = app.activeDocument.xmlElements[0],
        star, all, floats, cefloats, anyfloats;
        function traverse(t, p) {
            var r = [], i;
            if (p(t)) {
                r = r.concat(t);
            for (i=0; i<t.xmlElements.length; i++) {
                r = r.concat (traverse(t.xmlElements[i], p));
            return r;
        function dumplist(l) {
            var i,
                rv = [];
            rv.push("has "+l.length+" elements:");
            for (i=0; i<l.length; i++) {
                rv.push("  "+i+"\t"+l[i].toSpecifier()+
                    "\t"+l[i].markupTag.name);
            return rv.join("\n");
      star = x.evaluateXPathExpression("*");
      all = traverse(x,
          function() { return true; }
      floats = traverse(x,
           function(n) { return n.markupTag.name==="float"; }
      cefloats = traverse(x,
          function(n) { return n.markupTag.name==="ce:float"; }
      anyfloats = traverse(x,
          function(n) { return n.markupTag.name.match(/float$/); }
      $.writeln("star: "+dumplist(star));
      $.writeln("all "+dumplist(all));
      $.writeln("floats "+dumplist(floats));
      $.writeln("cefloats "+dumplist(cefloats));
      $.writeln("anyfloats "+dumplist(anyfloats));
    So, if you run this on a document with an XML schema like this:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Root>
      <ce:float>A</ce:float>
      <ce:float>B</ce:float>
      <float>AC</float>
      <float>Ad</float>
      <ce:float>Af</ce:float>
      <div>
        <ce:float>Ai</ce:float>
        <float>Ag</float>
      </div>
    </Root>
    It gives you this output:
    star: has 3 elements:
      0     /document[@id=1]/XML-element[@id=2]/XML-element[@id=5]     float
      1     /document[@id=1]/XML-element[@id=2]/XML-element[@id=6]     float
      2     /document[@id=1]/XML-element[@id=2]/XML-element[@id=11]     div
    all has 9 elements:
      0     /document[@id=1]/XML-element[0]     Root
      1     /document[@id=1]/XML-element[0]/XML-element[0]     ce:float
      2     /document[@id=1]/XML-element[0]/XML-element[1]     ce:float
      3     /document[@id=1]/XML-element[0]/XML-element[2]     float
      4     /document[@id=1]/XML-element[0]/XML-element[3]     float
      5     /document[@id=1]/XML-element[0]/XML-element[4]     ce:float
      6     /document[@id=1]/XML-element[0]/XML-element[5]     div
      7     /document[@id=1]/XML-element[0]/XML-element[5]/XML-element[0]     ce:float
      8     /document[@id=1]/XML-element[0]/XML-element[5]/XML-element[1]     float
    floats has 3 elements:
      0     /document[@id=1]/XML-element[0]/XML-element[2]     float
      1     /document[@id=1]/XML-element[0]/XML-element[3]     float
      2     /document[@id=1]/XML-element[0]/XML-element[5]/XML-element[1]     float
    cefloats has 4 elements:
      0     /document[@id=1]/XML-element[0]/XML-element[0]     ce:float
      1     /document[@id=1]/XML-element[0]/XML-element[1]     ce:float
      2     /document[@id=1]/XML-element[0]/XML-element[4]     ce:float
      3     /document[@id=1]/XML-element[0]/XML-element[5]/XML-element[0]     ce:float
    anyfloats has 7 elements:
      0     /document[@id=1]/XML-element[0]/XML-element[0]     ce:float
      1     /document[@id=1]/XML-element[0]/XML-element[1]     ce:float
      2     /document[@id=1]/XML-element[0]/XML-element[2]     float
      3     /document[@id=1]/XML-element[0]/XML-element[3]     float
      4     /document[@id=1]/XML-element[0]/XML-element[4]     ce:float
      5     /document[@id=1]/XML-element[0]/XML-element[5]/XML-element[0]     ce:float
      6     /document[@id=1]/XML-element[0]/XML-element[5]/XML-element[1]     float

  • Through DOM how to frame namespace of any element

    Hi
    I am using javamapping and tried to create target document by using Document class method "createElementNS". However, I failed to create the same. Can any one assist me in creation of Namespace for a xml. it's gr8 in case u provide any reference/link .
    Thanks

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                DocumentBuilder db = dbf.newDocumentBuilder();
                Document soapDoc = db.newDocument();
                Element soapEnv = soapDoc.createElementNS("http://www.w3.org/2001/12/soap-envelope","Envelope");
                Element soapHeader = soapDoc.createElementNS("http://www.w3.org/2001/12/soap-envelope","Header");
                soapEnv.appendChild(soapHeader);
                Element soapBody = soapDoc.createElementNS("http://www.w3.org/2001/12/soap-envelope","Body");
                soapEnv.appendChild(soapBody);
                Element hotelBookingResponse = soapDoc.createElementNS(
                                     "http://www.MyHotel.com/partnerservice/",
                                     "GetSpecialDiscountedBookingForPartnersResponse");
                hotelBookingResponse.appendChild(
                    soapDoc.createElementNS(
                        "http://www.MyHotel.com/partnerservice/",
                        "BookingDetails"));
                soapBody.appendChild(hotelBookingResponse);
                soapDoc.appendChild(soapEnv);
    http://webservices.xml.com/2003/11/25/examples/Listing1.html

  • NS0 namespace in every element after mapping

    Hi All,
    We have a scenario IDOC --> XML file on a file share. I created a free style data type for the XML message and the mapping objects. When I test the message mapping, every XML element gets the ns0 namespace before the tagname. The namespace prefix is ok to be mentioned on a root level, but not with every element. Can we configure something that this behavior is not occuring anymore?
    Example current result:
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:OrderCreateNotification xmlns:ns0="urn:mc-nl:procurement:boras:boras">
    <ns0:OrderNumber>4550000037</ns0:OrderNumber>
    <ns0:DocumentDate>20140722</ns0:DocumentDate>
    <ns0:OrderItem>
         <ns0:ItemNumber>00001</ns0:ItemNumber>
         <ns0:Unit>ST</ns0:Unit>
         <ns0:Quantity>100.000</ns0:Quantity>
         <ns0:NettPrice>10000</ns0:NettPrice>
         <ns0:PurchaseRequisitionItemNumber>00000</ns0:PurchaseRequisitionItemNumber>
         <ns0:TaxRate>21.00</ns0:TaxRate>
    </ns0:OrderItem>
    </ns0:OrderCreateNotification>
    I expected to have it like this:
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:OrderCreateNotification xmlns:ns0="urn:mc-nl:procurement:boras:boras">
    <OrderNumber>4550000037</OrderNumber>
    <DocumentDate>20140722</DocumentDate>
    <OrderItem>
         <ItemNumber>00001</ItemNumber>
         <Unit>ST</Unit>
         <Quantity>100.000</Quantity>
         <NettPrice>10000</NettPrice>
         <PurchaseRequisitionItemNumber>00000</PurchaseRequisitionItemNumber>
         <TaxRate>21.00</TaxRate>
    </OrderItem>
    </ns0:OrderCreateNotification>
    With the data type it is possible to define the property "qualify schema", but it doesn't seem to do anything.
    I know of the possibility to use the XML Anonimizer module, but I was hoping that we can configure this in a standard way.
    kind regards,
    Mark

    Hi All,
    Issue was solved by defining the value "None" in the Qualify Schema option + reimporting the message types into the message mapping after making the Qualify Schema change. The XML structures didn't got refreshed automatically.
    Everything is working normally now with the ns prefix only on root level.
    Regards,
    Mark

Maybe you are looking for