xi:include is not included while evaluating XPath.

Oxygen general issues.
mveerasamy
Posts: 10
Joined: Fri Oct 02, 2009 12:24 am

xi:include is not included while evaluating XPath.

Post by mveerasamy »

I am having problem in evaluating XPath while using xi:include.
My Xml will look like this:

Code: Select all

<test>
<child>Child1 </child>
<child>Child2 </child>
<xi:include href=”S123.xml”/>
</test>
Where S123.xml contains the following:

Code: Select all

 <child>Child3 </child>
<child>Child4 </child>
Now my question is when I use the following code I got only the Child1 and Child2.

Code: Select all

String xPath=” //child”;
authorAccess.getDocumentController().evaluateXPath(xPath, false, false, false);
authorAccess.getDocumentController().findNodesByXPath(xPath, false, false, false);
What should I have to do to get all child(Child1-4) elements?

[Note: But Oxygen’s xpath builder provides all 4 child elements when I search with the same Xpath. Is your UI using different API?]
Radu
Posts: 9041
Joined: Fri Jul 09, 2004 5:18 pm

Re: xi:include is not included while evaluating XPath.

Post by Radu »

Hi,

We use Saxon 9 and XPath 2.0 to run XPath's from the Author API but the XPaths are only performed on the current document's content.
You can easily create a method to iterate all nodes (which also goes into the referenced content) and find all sect1's like:

Code: Select all


  /**
* @see ro.sync.ecss.extensions.api.AuthorOperation#doOperation(ro.sync.ecss.extensions.api.AuthorAccess, ro.sync.ecss.extensions.api.ArgumentsMap)
*/
public void doOperation(AuthorAccess authorAccess, ArgumentsMap args)
throws IllegalArgumentException, AuthorOperationException {
List<AuthorNode> allSect1s = new ArrayList<AuthorNode>();
findSect1s(authorAccess.getDocumentController().getAuthorDocumentNode().getRootElement(), allSect1s);
}

private void findSect1s(AuthorNode node, List<AuthorNode> allSect1s) {
if("sect1".equals(node.getName())) {
allSect1s.add(node);
} else if(node instanceof AuthorParentNode) {
List<AuthorNode> contentNodes = ((AuthorParentNode)node).getContentNodes();
for (int i = 0; i < contentNodes.size(); i++) {
findSect1s(contentNodes.get(i), allSect1s);
}
}
}
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
mveerasamy
Posts: 10
Joined: Fri Oct 02, 2009 12:24 am

Re: xi:include is not included while evaluating XPath.

Post by mveerasamy »

Thanks for the reply.

Also i am having one more problem. I am trying to set my custom Name Space to my root node. there is method getNamespace() availavle in AuthorNode. but there is no setNamespace() there. is there any setNamespace() available anywhere?.
Thanks in advance,
Muthu
Radu
Posts: 9041
Joined: Fri Jul 09, 2004 5:18 pm

Re: xi:include is not included while evaluating XPath.

Post by Radu »

Hi Muthu,

The code should be something like:

Code: Select all


    AuthorElement root = authorAccess.getDocumentController().getAuthorDocumentNode().getRootElement();
String searchPrefix = "";
if(root.getName().indexOf(":") != -1) {
searchPrefix = ":" + root.getName().substring(0, root.getName().indexOf(":"));
}
int rootAttrs = root.getAttributesCount();
for (int i = 0; i < rootAttrs; i++) {
String attr = root.getAttributeAtIndex(i);
//Search for the xmlns declaration on the element
if(attr.startsWith("xmlns" + searchPrefix)) {
//Found the attribute which maps to the root namespace
authorAccess.getDocumentController().setAttribute(attr, new AttrValue("NEW_NAMESPACE_VALUE"), root);
break;
}
}
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply