Xpath compilation for Child element with namespace + Getting error - Prefix must resolve to a namespace: ns2 - dom

Sample
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<ns2:bookStore xmlns:ns2="http://bookstore.com/schemes">
<ns2:book id="1">
<ns2:name>Data Structure</ns2:name>
</ns2:book>
<ns2:book id="2">
<ns2:name>Java Core</ns2:name>
</ns2:book>
</ns2:bookStore>
</Root>
Java code
XPathExpression expr =
xpath.compile("//Root/ns2:bookStore/ns2:book/ns2:name/text()");
I get Prefix must resolve to a namespace: ns2 error with above xml with Root
tag. By removing the Root tag I'm able to parse the data. Any help would be appreciated without modifying the XML file.

Related

Deploying communities using package.xml

I am trying to retrieve Salesforce communities names 'XXX Community' from one org into VS Code and subsequently want to deploy it into another org.
However, when I use the sfdx force:source:retrieve -u DemoMaster -x ./package.xml command, for the below package.xml file, I get the following error:
Entity of type 'CustomSite' named 'XXX_Community_Test' cannot be found
Entity of type 'SiteDotCom' named 'XXX_Community_Test1' cannot be found
Only the network and network branding elements got retrieved.
The package.xml file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>XXX Community</members>
<name>Network</name>
</types>
<types>
<members>XXX_Community_Test</members>
<name>CustomSite</name>
</types>
<types>
<members>XXX Community_Test1</members>
<name>SiteDotCom</name>
</types>
<types>
<members>cbXXX_Community</members>
<name>NetworkBranding</name>
</types>
<version>48.0</version>
</Package>
Any help appreciated!
D

What is wrong with my layer.xml from netbeans?

I try to create a new palette in netbeans 10, but the following 2 errors don't allow me to compile the project:
Document root element "folder", must match DOCTYPE root "JavaPalette". [3]
The markup in the document following the root element must be well-formed. [11]
My XML looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
<folder name="JavaPalette">
<folder name="Items">
<attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.javasourcefilepalette.Bundle"/>
<file name="Item.xml" url="resources/Item.xml">
<attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.javasourcefilepalette.Bundle"/>
</file>
</folder>
</folder>
<filesystem/>
I have no clue what both error messages mean, but i did exactly what is said in the tutorial.
Online validation of the xml file also shows that error.
https://platform.netbeans.org/tutorials/nbm-palette-api2.html
I didn´t followed the tutorial, but as far as i can tell, your filesystem tag is not valid. If you take a look at the DTD you can see that the element filesystem isn´t declared as EMPTY (for more information you can read more about it here). So you have to provide a start and end tag. In your posted example you are only using <filesystem/> which isn´t allowed.
You have to change the xml as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
<filesystem>
<folder name="JavaPalette">
<folder name="Items">
<attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.javasourcefilepalette.Bundle"/>
<file name="Item.xml" url="resources/Item.xml">
<attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.javasourcefilepalette.Bundle"/>
</file>
</folder>
</folder>
</filesystem>

Powershell: XPath cannot select when element has "xmlns" tag?

I've got a very simple xml, as below:
<?xml version="1.0" encoding="utf-8"?>
<First>
<Second>
<Folder>today</Folder>
<FileCount>10</FileCount>
</Second>
<Second>
<Folder>tomorrow</Folder>
<FileCount>90</FileCount>
</Second>
<Second>
<Folder>yesterday</Folder>
<FileCount>22</FileCount>
</Second>
</First>
Then I have a powershell script to select "Folder" element:
[xml]$xml=Get-Content "D:\m.xml"
$xml.SelectNodes("//Folder")
It outputs:
#text
-----
today
tomorrow
yesterday
No problem. But if I change the xml file to add "xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to "First" like below:
<?xml version="1.0" encoding="utf-8"?>
<First xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Second>
<Folder>today</Folder>
<FileCount>10</FileCount>
</Second>
<Second>
<Folder>tomorrow</Folder>
<FileCount>90</FileCount>
</Second>
<Second>
<Folder>yesterday</Folder>
<FileCount>22</FileCount>
</Second>
</First>
Then, my powershell script outputs nothing.
Why? How to change my powershell script to support this xmlns?
Thanks a lot.
What you added is default namespace. Unlike prefixed namespace, descendant elements inherit ancestor default namespace implicitly, unless otherwise specified (using explicit prefix or local default namespace that points to different URI).
To select element in namespace, you'll need to define prefix that point to the namespace URI and use that prefix properly in your XPath, for example :
$ns = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
$ns.AddNamespace("d", $xml.DocumentElement.NamespaceURI)
$xml.SelectNodes("//d:Folder", $ns)

How do I config xml namespace for a smooks input file using WSO2?

I couldn't find any advices on how to setup Smooks (on WSO2 Developer Studio 3.1) in order to it properly read a xml input which has a namespace declaration.
Without the namespace the transformation works just fine!
By informing the xmlns in the input, I get this exception:
Error on line 5, column 19 in free-marker-template
Expecting a string, date or number here, Expression .vars["order"]["order-items/order-item/#id"] is instead a freemarker.ext.dom.NodeListModel
The problematic instruction:
----------
==> ${.vars["order"]["order-items/order-item/#id"]} [on line 5, column 17 in free-marker-template]
These are both my input and output:
<order id='444' xmlns="http://example.com">
<header>
<customer number="555">Amila</customer>
</header>
<order-items>
<order-item id='1'>
<product>1</product>
<quantity>2</quantity>
<price>400</price>
</order-item>
</order-items>
</order>
<salesorder>
<details>
<orderid></orderid>
<customer>
<id></id>
<name></name>
</customer>
</details>
<itemList>
<item>
<id></id>
<productId></productId>
<quantity></quantity>
<price></price>
</item>
</itemList>
</salesorder>
I've also tried Smooks core´s namespace declarations as per Smooks site:
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd"
xmlns:core="http://www.milyn.org/xsd/smooks/smooks-core-1.4.xsd"
>
<core:namespaces>
<core:namespace prefix="ex" uri="http://example.com/"/>
</core:namespaces>
But it seems not to be supported in the IDE since the configuration editor raises this exception:
-Value 'org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl#53abd5a9 (mixed: null, anyAttribute: null)' is not legal. (platform:/resource/Corp/smooks-config.xml,6,20)
Well, any idea?
Instead of Smooks, can't you use a XSLT? It will avoid the namespace issue you have.

Remove Home element from navigation in Zend_Navigation

Can I remove the Home element from the XML file containing menus.
<?xml version="1.0" encoding="UTF-8"?>
<configdata>
<nav>
<label>HOME</label>
<controller>index</controller>
<action>index</action>
<id>root</id>
<pages>...</pages>
....
When I delete it from the xml file (from line 4 to 7), I get an exception
Zend_Navigation_Exception: Invalid argument: Unable to determine class to instantiate in C:\www\project\library\Zend\Navigation\Page.php on line 235
Well , you remove lines related to Home element in addition to the <nav> tag !!!
and then XML file becomes
<?xml version="1.0" encoding="UTF-8"?>
<configdata>
<menu1>...</menu1>
<menu2>...</menu2>
...
</configdata>