开发者

Efficient XML Parsing for specific xsi:type

开发者 https://www.devze.com 2023-01-31 23:39 出处:网络
All, I have a directory of large xml files with the following setup: <io:InfoObjects xmlns:crole=\"http://enterprise.businessobjects.com/3.0/customrole\"

All,

I have a directory of large xml files with the following setup:

<io:InfoObjects xmlns:crole="http://enterprise.businessobjects.com/3.0/customrole" 
 xmlns:fo="http://enterprise.businessobjects.com/3.0/folder"  
 xmlns:io="http://enterprise.businessobjects.com/3.0/infoobject" 
 xmlns:md.dc="http://enterprise.businessobjects.com/3.0/metadata.dataconnection"  
 xmlns:un="http://enterprise.businessobjects.com/3.0/universe" 
 xmlns:wi="http://enterprise.businessobjects.com/3.0/webi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xsi:schemaLocation="http://enterprise.businessobjects.com/3.0/customrole BusinessObjects_CustomRole.xsd  
 http://enterprise.businessobjects.com/3.0/folder BusinessObjects_Folder.xsd 
 http://enterprise.businessobjects.com/3.0/infoobject BusinessObjects_InfoObject.xsd  
 http://enterprise.businessobjects.com/3.0/metadata.dataconnection BusinessObjects_MetaData_DataConnection.xsd 
 http://enterprise.businessobjects.com/3.0/universe BusinessObjects_Universe.xsd 
 http://enterprise.businessobjects.com/3.0/webi BusinessObjects_Webi.xsd" version="1200" illegalCharsEncoded="true">
 <io:InfoObject xsi:type="wi:Webi">
  <io:ID>1</io:ID> 
  <io:Name>MyName</io:Name>
  <io:Description>NoDesc</io:Description>
 </io:InfoObject>
</io:InfoObjects>

Original Question: (in Java 1.5) I am currently using dom and parsing through each node/elemnt until i find my specific type of wi:Webi. This seems terribily enefficient and feel that I am missing a Java function that would allow me to simply extract all elements/nodes with the type of "wi:Webi". Is there a simpler solution?

Updates: I am starting to use XPath but, am having issues with the expression creation. So far I am trying:

xpath.compile("//*[@xsi:type='wi:Webi']");

According to othe开发者_JAVA百科r stackoverflow posts who had similar issues I need to define in my expression the namespace. I was hopeing that the *[@xsi:type] search would state for any child with type of wi:Webi return it as in the nodelist.


There's "runs fast and light" efficiency, then there's "developer writing fewer lines of code" efficiency. Which are you most concerned about?

If it's speed, look into SAX processing as it cannot be overstated how much more efficient it can be if your requirements can get by with it. It's quite a mental adjustment going from DOM to SAX but I recommend it.

Otherwise if you need to stick with DOM, look at XPath to easily extract all matching elements.

0

精彩评论

暂无评论...
验证码 换一张
取 消