x:include resolved xml document

Oxygen general issues.
guna@ebscohost.com
Posts: 27
Joined: Tue Nov 17, 2009 10:16 pm

x:include resolved xml document

Post by guna@ebscohost.com »

Hi,
I have a xml document, which has 10 x:includes.

I need an xml document String, will all x:include resolved with corresponding content.

I am wondering , it there a method in api to give this value.

example
sorcDoc.xml

<test>
<x:include href="S31.xml"/>
</text>


S31.xml
<hello>
how are you
</hello>




output i needed as xml String is
<test>
<hello>
how are you
</hello>
</test>

can you guide me, how to get this value?

Thanks
Guna
Radu
Posts: 9018
Joined: Fri Jul 09, 2004 5:18 pm

Re: x:include resolved xml document

Post by Radu »

Hi Guna,

You have API to get the XML content as a string from a document fragment but if the fragment contains xi:includes they are not expanded.
For each xi:include node you have to create a document fragment and serialize that one.

Here is some sample code which might give you an idea where to begin:

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 {
try {
AuthorDocumentFragment df = authorAccess.getDocumentController().createDocumentFragment(authorAccess.getDocumentController().getAuthorDocumentNode().getRootElement(), true);
String xmlFragWithXIIncludesNotExpanded = authorAccess.getDocumentController().serializeFragmentToXML(df);
List<String> xiIncludeContents = new ArrayList<String>();
findXIIncludes(authorAccess, xiIncludeContents, authorAccess.getDocumentController().getAuthorDocumentNode().getRootElement());
//Now you can merge the XIInclude contents back into the original content.
} catch (BadLocationException e) {
e.printStackTrace();
}
}

private void findXIIncludes(AuthorAccess authorAccess, List<String> xiIncludesContent, AuthorNode elem) throws BadLocationException {
if(elem.getName().equals("xi:include")) {
//Found xi:include.
AuthorDocumentFragment df = authorAccess.getDocumentController().createDocumentFragment(elem.getStartOffset() + 2, elem.getEndOffset() - 2);
xiIncludesContent.add(authorAccess.getDocumentController().serializeFragmentToXML(df));
} else if(elem instanceof AuthorParentNode){
List<AuthorNode> children = ((AuthorParentNode)elem).getContentNodes();
for (int i = 0; i < children.size(); i++) {
findXIIncludes(authorAccess, xiIncludesContent, children.get(i));
}
}
}
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply