Finding a particular attribute of tags within the document
Post here questions and problems related to oXygen frameworks/document types.
-
- Posts: 17
- Joined: Fri Dec 29, 2017 11:16 am
Finding a particular attribute of tags within the document
Post by pramanikhimangshu »
Hi,
I need to find a particular type of attribute from the any xml tags of dita document in Oxygen Web Author.
I tried doing it by JSAPI modifying framework.js:
Getting JS error:
workspace-c71778b94e.js:1359 Uncaught TypeError: Cannot read property 'nextElementSibling' of null
at Object.sync.model.XmlDom.getNextSibling (workspace-c71778b94e.js:1359)
at Object.sync.model.XmlDom.getChildNodes (workspace-c71778b94e.js:1359)
at sync.api.dom.Element.sync.api.dom.Node.getChildNodes (workspace-c71778b94e.js:1534)
Is it the correct way to find this or any other way is there.
Can you please let me know the best way to do this?
I need to find a particular type of attribute from the any xml tags of dita document in Oxygen Web Author.
I tried doing it by JSAPI modifying framework.js:
Code: Select all
function printAllAttrVals(rootNode)
{
if(rootNode == null || rootNode == undefined || rootNode.id == undefined)
return;
console.log(rootNode);
console.log(rootNode.id);
console.log(rootNode.getContent());
console.log(rootNode.getTagName());
console.log(rootNode.getAttribute("<attribute>"));
var children = rootNode.getChildNodes();
if(children.length == 0)
{
}
else
{
for(var xtrip = 0;xtrip<children.length;xtrip++)
{
printAllAttrVals(children[xtrip]);
}
}
}
var checkNode = globalAttrs.selectedElement;
while(checkNode && checkNode.getTagName() != 'conbody')
{
console.log(checkNode.getTagName());
checkNode = checkNode.getParent();
}
printAllAttrVals(checkNode);//[calling from conbody]
workspace-c71778b94e.js:1359 Uncaught TypeError: Cannot read property 'nextElementSibling' of null
at Object.sync.model.XmlDom.getNextSibling (workspace-c71778b94e.js:1359)
at Object.sync.model.XmlDom.getChildNodes (workspace-c71778b94e.js:1359)
at sync.api.dom.Element.sync.api.dom.Node.getChildNodes (workspace-c71778b94e.js:1534)
Is it the correct way to find this or any other way is there.
Can you please let me know the best way to do this?
-
- Posts: 515
- Joined: Wed May 20, 2009 2:40 pm
Re: Finding a particular attribute of tags within the document
Hi,
Can you please give us more details about what you are trying to achive?
More context will be helpful in order to guide you to use some API.
Best Regards,
Mihaela
Can you please give us more details about what you are trying to achive?
More context will be helpful in order to guide you to use some API.
Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
http://www.oxygenxml.com
-
- Posts: 17
- Joined: Fri Dec 29, 2017 11:16 am
Re: Finding a particular attribute of tags within the document
Post by pramanikhimangshu »
HI Mihaela,
I am trying to customize the dita framework. I am trying to get the dita tags(sync.api.dom.Element) which has a particular attribute in whole dita document.
Eg: If I want to get all the Dita tags which are links. So I would like to search for href attribute in all the tags and whichever tags have the href attribute I will Store in some variable. I want to know how to achieve this, to start from root tag and go through all tags searching for the attr? Or there is any other way to perform this.
Considering if I have a concept Dita topic I started from <concept> in my current implementation, in some case while calling getChildNodes on some nodes getting this Error:
workspace-c71778b94e.js:1359 Uncaught TypeError: Cannot read property 'nextElementSibling' of null
at Object.sync.model.XmlDom.getNextSibling (workspace-c71778b94e.js:1359)
at Object.sync.model.XmlDom.getChildNodes (workspace-c71778b94e.js:1359)
at sync.api.dom.Element.sync.api.dom.Node.getChildNodes (workspace-c71778b94e.js:1534)
I hope I can explain it.
Regards,
Himangshu.
I am trying to customize the dita framework. I am trying to get the dita tags(sync.api.dom.Element) which has a particular attribute in whole dita document.
Eg: If I want to get all the Dita tags which are links. So I would like to search for href attribute in all the tags and whichever tags have the href attribute I will Store in some variable. I want to know how to achieve this, to start from root tag and go through all tags searching for the attr? Or there is any other way to perform this.
Considering if I have a concept Dita topic I started from <concept> in my current implementation, in some case while calling getChildNodes on some nodes getting this Error:
workspace-c71778b94e.js:1359 Uncaught TypeError: Cannot read property 'nextElementSibling' of null
at Object.sync.model.XmlDom.getNextSibling (workspace-c71778b94e.js:1359)
at Object.sync.model.XmlDom.getChildNodes (workspace-c71778b94e.js:1359)
at sync.api.dom.Element.sync.api.dom.Node.getChildNodes (workspace-c71778b94e.js:1534)
I hope I can explain it.
Regards,
Himangshu.
-
- Posts: 517
- Joined: Thu Sep 04, 2014 4:22 pm
Re: Finding a particular attribute of tags within the document
Post by cristi_talau »
Hello,
We have to kinds of APIs, a limited client-side JS API and a more powerful server-side Java API. The JS API currently does not allow you to easily make a list of nodes with a certain attribute.
If we understand your end-goal, we can either suggest a more suitable JS or Java API, or we can improve the existing API to accomodate your use-case, if there is no alternative. To this end we need to understand your end-goal. The kind of end-goal that we would be interested in is something like
- I am trying to create a side-view with all the elements with links
- I am trying to implement an operation that changes the attributes of all elements in bulk
- I am trying to validate that all elements have a valid attribute
- etc.
Best,
Cristian
We have to kinds of APIs, a limited client-side JS API and a more powerful server-side Java API. The JS API currently does not allow you to easily make a list of nodes with a certain attribute.
If we understand your end-goal, we can either suggest a more suitable JS or Java API, or we can improve the existing API to accomodate your use-case, if there is no alternative. To this end we need to understand your end-goal. The kind of end-goal that we would be interested in is something like
- I am trying to create a side-view with all the elements with links
- I am trying to implement an operation that changes the attributes of all elements in bulk
- I am trying to validate that all elements have a valid attribute
- etc.
Best,
Cristian
-
- Posts: 17
- Joined: Fri Dec 29, 2017 11:16 am
Re: Finding a particular attribute of tags within the document
Post by pramanikhimangshu »
Hi,
I am trying to create internal content linking in the Dita Document.
To link a internal content, I need to display all the elements having ID attribute to the user to select which element to use and create a link of that element in the currently selected text.
This is the use-case: A example document, which have three elements with ID attribute -
ID TAG Name
---------------------------
test1 dt
test2 dt
table1 table
User selects any one of those and a link is created at the selection : with <xref href=ditaID/#<ID of Selected item>/>
For this I need to find all the elements with ID attr and display it to the user to select from, I am trying to accomplish this using JS-api:
rootNode (of type sync.api.dom.Element) is the root tag.
globalAttrs.listOfIDs is the array where I store the IDs.
With this code I can establish the use case. I would like to know if there is any better way to establish this use case.
I got error at the position : // console.log(error); stating :
for some empty elements like <p></p>. Thus catching the error solved the issue but I want to confirm if this customization is full-proof or there is some better alternative way.
Thank you.
Regards,
Himangshu
I am trying to create internal content linking in the Dita Document.
To link a internal content, I need to display all the elements having ID attribute to the user to select which element to use and create a link of that element in the currently selected text.
This is the use-case: A example document, which have three elements with ID attribute -
ID TAG Name
---------------------------
test1 dt
test2 dt
table1 table
User selects any one of those and a link is created at the selection : with <xref href=ditaID/#<ID of Selected item>/>
For this I need to find all the elements with ID attr and display it to the user to select from, I am trying to accomplish this using JS-api:
Code: Select all
function collectNodeID(rootNode)
{
if(rootNode == null || rootNode == undefined || rootNode.id == undefined || rootNode.getType() != goog.dom.NodeType.ELEMENT)
return;
if(rootNode.getAttribute("id"))
{
globalAttrs.listOfIDs.push(rootNode);
}
var children;
try
{
children = rootNode.getChildNodes();
}
catch(error)
{
// console.log(error);
children = [];
}
if(children.length == 0)
{
return;
}
else
{
for(var xtrip = 0;xtrip<children.length;xtrip++)
{
collectNodeID(children[xtrip]);
}
}
}
globalAttrs.listOfIDs is the array where I store the IDs.
With this code I can establish the use case. I would like to know if there is any better way to establish this use case.
I got error at the position : // console.log(error); stating :
Code: Select all
workspace-c71778b94e.js:1359 Uncaught TypeError: Cannot read property 'nextElementSibling' of null
at Object.sync.model.XmlDom.getNextSibling (workspace-c71778b94e.js:1359)
at Object.sync.model.XmlDom.getChildNodes (workspace-c71778b94e.js:1359)
at sync.api.dom.Element.sync.api.dom.Node.getChildNodes (workspace-c71778b94e.js:1534)
Thank you.
Regards,
Himangshu
-
- Posts: 517
- Joined: Thu Sep 04, 2014 4:22 pm
Re: Finding a particular attribute of tags within the document
Post by cristi_talau »
Hello,
Thanks for the detailed explanation. Now it makes sense. I managed to reproduce the problem you reported. The fix will be shipped in the next version of Web Author. Meanwhile you can include this patch in your code:
This patch works only with version '19.1'. Once you upgrade, you can safely remove it.
Best,
Cristian
Thanks for the detailed explanation. Now it makes sense. I managed to reproduce the problem you reported. The fix will be shipped in the next version of Web Author. Meanwhile you can include this patch in your code:
Code: Select all
if (sync.api.Version === 'v19.1.0') {
sync.model.XmlDom.getChildNodes = function(elem) {
var children = [];
var child = sync.model.XmlDom.getFirstChild(elem);
if (child) {
do {
children.push(child);
child = sync.model.XmlDom.getNextSibling(child);
} while (child !== null);
}
return children;
};
}
Best,
Cristian
Return to “SDK-API, Frameworks - Document Types”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service